Guest User

Untitled

a guest
Jun 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. /*
  5. Project Euler
  6. Problem 5:
  7. "2520 is the smallest number that can be divided by each of
  8. the numbers from 1 to 10 without any remainder.
  9.  
  10. What is the smallest number that is evenly divisible by all
  11. of the numbers from 1 to 20?"
  12.  
  13. */
  14.  
  15. bool divisibleByAll(__int64 number, int to);
  16.  
  17. void main () {
  18.  
  19. int max_number = 20; // ...be divided by each of the numbers from 1 to x
  20. __int64 count = 1;
  21.  
  22. while (!divisibleByAll(count, max_number)) {
  23. //cout << "^ Just called notDivisibleByAll(" << count << ", " << max_number << ")" << endl << endl;
  24. count++;
  25. }
  26. //cout << "^ Just called notDivisibleByAll(" << count << ", " << max_number << ")" << endl << endl;
  27.  
  28. cout << count;
  29.  
  30. int stopCommandPromptFromClosing;
  31. cin >> stopCommandPromptFromClosing;
  32.  
  33. }
  34.  
  35. bool divisibleByAll(__int64 number, int to) {
  36.  
  37. for (int i = 2; i <= to; i++) {
  38. //cout << "\tChecking " << i << " against " << number << " ( = " << number % i << ")" << endl;
  39. if (number % i > 0) {
  40. //cout << "Returning true because " << number << " % " << i << " == 1" << endl;
  41. return false;
  42. }
  43. }
  44.  
  45. //cout << "Returning false! They are all divisible!" << endl;
  46. return true;
  47.  
  48. }
Add Comment
Please, Sign In to add comment