Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- /*
- Project Euler
- Problem 5:
- "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?"
- */
- bool divisibleByAll(__int64 number, int to);
- void main () {
- int max_number = 20; // ...be divided by each of the numbers from 1 to x
- __int64 count = 1;
- while (!divisibleByAll(count, max_number)) {
- //cout << "^ Just called notDivisibleByAll(" << count << ", " << max_number << ")" << endl << endl;
- count++;
- }
- //cout << "^ Just called notDivisibleByAll(" << count << ", " << max_number << ")" << endl << endl;
- cout << count;
- int stopCommandPromptFromClosing;
- cin >> stopCommandPromptFromClosing;
- }
- bool divisibleByAll(__int64 number, int to) {
- for (int i = 2; i <= to; i++) {
- //cout << "\tChecking " << i << " against " << number << " ( = " << number % i << ")" << endl;
- if (number % i > 0) {
- //cout << "Returning true because " << number << " % " << i << " == 1" << endl;
- return false;
- }
- }
- //cout << "Returning false! They are all divisible!" << endl;
- return true;
- }
Add Comment
Please, Sign In to add comment