角谷猜想

来源:互联网 发布:思归软件下载 编辑:程序博客网 时间:2024/05/16 10:19

角谷猜想

Time Limit:1000MS Memory Limit:65536K
Total Submit:224 Accepted:145

Description

  所谓的角谷猜想是:对于任意大于1的自然数n,若n为奇数,则将n变为3*n+1,否则将n变为n的一半。经过若干次这样的变换,一定会使n变为1。
  输入n,输出经过几次变换之后n变为1

Input

Output

Sample Input

90

Sample Output

17

#include<iostream>using namespace std;int main(){    int i,j,n,s,t;    cin>>n;    s=0;    while (n!=1)    {        if (n%2==0)        {            s++;            n=n/2;        }        else        {            s++;            n=n*3+1;        }    }    cout<<s;    return 0;}
0 0