-
Notifications
You must be signed in to change notification settings - Fork 0
/
ID_#5.c
31 lines (28 loc) · 800 Bytes
/
ID_#5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <iostream>
using namespace std;
int isEvenlyDivisible(int num){
int flag = 1;
for(int i = 1; i <= 20; i++){
if(num % i != 0){
flag = 0;
break;
}
}
return flag;
}
int main(){
int smallest = 0;
for(int i = 2520; ; i++){ // according to the problem we know that
// 2520 is the smallest number that can be divided by each the numbers
// from 1 to 10 without any remainder. Thus we know that the smallest
// positve number that is evenly divisible by all of the numbers from
// 1 to 20 must be greater than 2520
if(isEvenlyDivisible(i)){
smallest = i;
break;
}
}
cout << "The smallest positive number that is evenly divisible by all the number from 1 to 20 is: " << smallest << "." << endl;
return 0;
}