100分没过?

B2077 角谷猜想

him_out @ 2024-09-10 20:22:15

就很神奇,100分没过,代码如下。(水的题) 5、6TLE

#include<iostream>
using namespace std;

int main()
{
    int a;
    cin >> a;
    while(a != 1)
    {
        if(a%2==0)
            {
                cout << a << "/2=" << a/2 << endl;
                a/=2;
            }
        else
        {
            cout << a << "*3+1=" << a*3+1 << endl;
            a = a*3+1;
        }   
    }
    cout << "End";
    return 0;
}

by cinemaaa @ 2024-09-10 20:32:18

int改long long,int溢出后变为负数就卡在循环里了


by xingcode @ 2024-09-10 20:33:06

subtask没过


by him_out @ 2024-09-13 20:28:05

@cinemaaa thanks!!


|