要求:验证角谷猜想
任意正整数,偶数除2;奇数*3+1,最终得到1;
代码:
#include<iostream> //
#include<vector>
using namespace std;
int main()
{
int s, n=0;
cin >> s;
while (s!=1)
{
if (s % 2 == 0)
s *= 0.5;
else s = 3 * s + 1;
++n;
}
if (cout << "角谷猜想推理次数:" << n << endl)
cout << "m_geek 你最帅!" << endl;
else cout << "呸!m_geek 你个臭屌丝!" << endl;
system("pause");
return 0;
}
结果: