Last active
August 29, 2015 14:15
-
-
Save takanakahiko/f0ff47960709c57efc35 to your computer and use it in GitHub Desktop.
コラッツ予想(競技プログラミング 総集編2013 2.1)
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 characters
#include <iostream> | |
using namespace std; | |
int solve(int n); | |
int main(void){ | |
while(true){ | |
int n; cin >> n; | |
if(!n) | |
break; | |
cout << solve(n) << endl; | |
} | |
return 0; | |
} | |
int solve(int n){ | |
int count = 0; | |
while(n != 1){ | |
if(n % 2 == 0) | |
n = n / 2; | |
else | |
n = n * 3 + 1; | |
++count; | |
} | |
return count; | |
} |
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 characters
2 | |
3 | |
2398 | |
2385 | |
10000 | |
0 |
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 characters
cmd /k "g++ callatz.cc & a.exe < input.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment