Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int i;
  8. int x;
  9. int n;
  10. int superN;
  11. int superI;
  12.  
  13. superN = 0;
  14. superI = 0;
  15.  
  16.  
  17. for (i = 1; i <= 1000000; i++) {
  18.  
  19. x = i;
  20. n = 1;
  21.  
  22. do {
  23.  
  24. if (x % 2 == 0) {
  25.  
  26. x = x / 2;
  27.  
  28. }
  29.  
  30. if (x % 2 == 1 && x != 1) {
  31.  
  32. x = 3 * x + 1;
  33.  
  34. }
  35.  
  36. n++;
  37.  
  38. if (n > superN) {
  39.  
  40. superN = n;
  41. superI = i;
  42.  
  43.  
  44. }
  45.  
  46. } while (x != 1);
  47.  
  48. }
  49.  
  50. cout << "The number " << superI << " ran for " << superN << " terms.";
  51.  
  52. system("pause");
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement