-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_problemFive.cpp
More file actions
48 lines (41 loc) · 988 Bytes
/
_problemFive.cpp
File metadata and controls
48 lines (41 loc) · 988 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* 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
* by all of the numbers from 1 to 20?
*/
// Helper function - check if a number is divisible 1to20
bool isDivisibleMINtoMAX(int aNumber)
/**
* function returns true if aNumber is divisible by all the numbers
* from MIN_DIV to MAX_DIV.
* input -> aNumber int
*/
{
const int MAX_DIVISIBILITY = 21;
const int MIN_DIVISIBILITY = 2;
int something = 33;
int* pointer = &something;
for (size_t i = MIN_DIVISIBILITY; i < MAX_DIVISIBILITY; i++)
{
if (aNumber % i != 0) return false;
}
return true;
}
// main function - Go through every number from 1 to targetNumber checking
int smallestDivisibleNumber1to20()
{
int number = 20;
while (true)
{
if (isDivisibleMINtoMAX(number))
{
// you found it!
break;
}
number = number + 20;
}
return number;
}
// if it is divisible 1to20