PAT B1001害死人不偿命的(3n+1)猜想(满分15)

这道题入门级,十分简单。

#include<iostream>

using namespace std;

int main()
{
    
    
	int n;
	cin >> n;
	int count = 0;
	while (n > 1) 
	{
    
    
		if (n % 2 == 0)
			n /= 2;
		else
			n = (3 * n + 1) / 2;
		count++;
	}
	cout << count << endl;

	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_27538633/article/details/105935902