PAT乙级题解——1001 害死人不偿命的(3n+1)猜想 (15分)

PAT乙级题解——1001 害死人不偿命的(3n+1)猜想 (15分)_第1张图片

#include 
using namespace std;
int main(){
     
    int n;
    int step = 0;
    cin >> n;
    while(n!=1){
     
        if(n % 2 == 0){
     
        	//偶数
            n = n / 2;
        }else{
     
            //奇数
            n = (3 * n + 1) / 2;
        }
        step++;
     }
     cout << step;
     return 0;
}


你可能感兴趣的:(PAT)