75分求助!

B2077 角谷猜想

Weizimo1125 @ 2023-12-10 19:18:47

#include<iostream>
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<cmath>
using namespace std;
int main()
{
    int n;
    cin>> n;
    while(true)
    {
        if(n % 2 == 1)
        {
            printf("%d*3+1=%d\n",n,n*3+1);
            n *=3;
            n += 1;
        }
        else
        {
            printf("%d/2=%d\n",n,n / 2);
            n /= 2;
        }
        if(n == 1)
        {
            break;
        }
    }
    cout<<"End";
    return 0;
}

by Rieman_sum @ 2023-12-10 19:52:06

样例输入:1

正确输出:End


by ethanzyz @ 2023-12-10 19:54:26

你没有考虑n=1的情况。


by Weizimo1125 @ 2023-12-10 20:42:46

谢谢


|