pat-B1001- killed attractiveness of the (3n + 1) guess

Topic Link -> Link

Thinking

  1. According to the meaning of the questions to determine the cumulative parity.

Code

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>

using namespace std;

int main(){
    int n,count=0;
    scanf("%d",&n);
    while(n!=1){
        if(n%2==0){
            n/=2;
            count++;
        }
        else {
            n=(3*n+1)/2;
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}
Released eight original articles · won praise 1 · views 124

Guess you like

Origin blog.csdn.net/MichealWu98/article/details/104010107