Project Euler - problem 005

August 1st, 2007 by Daniel

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 number that is evenly divisible by all of the numbers from 1 to 20?

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
32
33
34
 
#include <iostream>
using namespace std;
 
#define interval 10
 
//define methods:
bool isDivisible(int num);
 
int main ()
{
int res(1);
 
while( ! isDivisible(res) ){
res++;
}
 
cout << "resultatet er ";
cout << res << "\n";
 
return 0;
}
 
 
 
//methods
bool isDivisible(int num){
for(int i = 2; i <= interval; i ++){
if( num % i != 0){
return false;
}
}
return true;
}

2 Responses to “Project Euler - problem 005”

  1. Err, your program does only for 1 to 10 again? But that’s provided!

  2. Harsh: Just change interval to 20

Leave a Response