PAT-B1001-は(3N + 1)の推測の魅力を殺しました

トピックリンク - > リンク

思考

  1. 累積パリティを決定するために質問の意味によります。

コード

#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;
}
リリース8元の記事 ウォンの賞賛1 ビュー124

おすすめ

転載: blog.csdn.net/MichealWu98/article/details/104010107