Deprecated: Assigning the return value of new by reference is deprecated in /customers/dahoiv.net/dahoiv.net/httpd.www/programmering/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /customers/dahoiv.net/dahoiv.net/httpd.www/programmering/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /customers/dahoiv.net/dahoiv.net/httpd.www/programmering/wp-includes/theme.php on line 507
Project Euler - problem 005

Project Euler - problem 005

August 1st, 2007 by Daniel Høyer Iversen

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;
}
Do you want to use this code?

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