pat乙级1001 害死人不偿命的(3n+1)猜想

版权声明:听说这里让写版权声明~~~ https://blog.csdn.net/m0_37691414/article/details/83686345

水题不知道怎么写题解,索性以后觉得很水的题都不写题解,但是有趣的水题还是会写题解的。。。

#include<iostream>
#include<cstdio>
using namespace std;
int n;
int main(){
	freopen("data.in", "r", stdin);
	while(scanf("%d", &n) == 1){
		int cnt = 0;
		while(n != 1){
			cnt++;
			if(n & 1) n = 3 * n + 1;;
			n >>= 1;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37691414/article/details/83686345