Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int i;
- int x;
- int n;
- int superN;
- int superI;
- superN = 0;
- superI = 0;
- for (i = 1; i <= 1000000; i++) {
- x = i;
- n = 1;
- do {
- if (x % 2 == 0) {
- x = x / 2;
- }
- if (x % 2 == 1 && x != 1) {
- x = 3 * x + 1;
- }
- n++;
- if (n > superN) {
- superN = n;
- superI = i;
- }
- } while (x != 1);
- }
- cout << "The number " << superI << " ran for " << superN << " terms.";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement