There is no problem when I input a number smaller than 12 but when I input something bigger the code returns with no output without any error. What's the problem?
Sample output I am getting -
Sample 1 -
1 13
Press any key to continue....
Sample 2 -
1 12
27720
Press any key to continue....
Sample 3 -
1 10
2520
Press any key to continue....
More Information - Actually this is an Question from project Euler's Hackerrank Contest - Project Euler #5 - Smallest Multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from to N?
Input Format
First line contains T that denotes the number of test cases. This is followed by T lines, each containing an integer, N.
Constraints -
1 <= T <= 10 1 <= N <= 40
Output Format
Print the required answer for each test case.
Sample Input 0
2 3 10
Sample Output 0
6 2520
Here is my solution -
#include <bits/stdc++.h>
using namespace std;
long smallest_multiple(int n, long num){
for(int i = 1; i <= n; i++){
if(num % i != 0){
while(num % i != 0){
num++;
return smallest_multiple(n, num);
}
}
}
return num;
}
int main(){
int t;
cin >> t;
for(int a0 = 0; a0 < t; a0++){
int n;
cin >> n;
long num = 2;
long int ans = smallest_multiple(n, num);
cout << ans << endl;
}
return 0;
}
Can you tell me what's going wrong and what can be done? P.S. Noob here, Please explain step by step. I'm just starting out.