Created
November 27, 2019 18:12
-
-
Save flyotlin/e8beecd5c1afd9650b350e12ede1f8b4 to your computer and use it in GitHub Desktop.
Revisions
-
flyotlin created this gist
Nov 27, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ #include <iostream> using namespace std; int three_n(int); int main() { int a, b; while(cin >> a >> b) { int temp, aa, bb; if(a > b) { bb = a; aa = b; } else { aa = a; bb = b; } int max = 0; for(int i = aa; i <= bb; i++) { max = (three_n(i) > max) ? three_n(i) : max; } cout << a << " " << b << " " << max << endl; } return 0; } int three_n(int n) { int count=0; while(n != 1) { if(n%2 == 1) { n = 3*n+1; count++; } else { n /= 2; count++; } } return count+1; }