Skip to content

Instantly share code, notes, and snippets.

@takanakahiko
Last active August 29, 2015 14:15
Show Gist options
  • Save takanakahiko/f0ff47960709c57efc35 to your computer and use it in GitHub Desktop.
Save takanakahiko/f0ff47960709c57efc35 to your computer and use it in GitHub Desktop.
コラッツ予想(競技プログラミング 総集編2013 2.1)
#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;
}
2
3
2398
2385
10000
0
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