大佬们快救救我!!!

B2077 角谷猜想

gaohuashengtx @ 2024-12-22 20:40:56

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    for(int i=1;;i++){
        if(n%2==0){
            cout<<n<<"/2="<<n/2<<endl;
            if(n/2==1)break;
            n/=2;
        }
        else{
            cout<<n<<"*3+1="<<n*3+1<<endl;
            n=n*3+1;
        }
    }
    cout<<"End";
      return 0;
}

by ChenHaoQi @ 2024-12-22 20:42:40

@gaohuashengtx 几分啊


by zxckhj114514 @ 2024-12-22 20:44:04

@ChenHaoQi75


by zxckhj114514 @ 2024-12-22 20:44:28


by zxckhj114514 @ 2024-12-22 20:45:23

先改long long类型


by zxckhj114514 @ 2024-12-22 20:46:15

int n -> long long n


by ChenHaoQi @ 2024-12-22 20:47:12

@gaohuashengtx n=1 的时候没判


by pika_ @ 2024-12-22 20:48:08

  1. int \to long long
  2. if(n/2==1)break;要放在外面
    hack:
    input:
    1
    your:
    1*3+1=4
    4/2=2
    2/2=1
    End

    ans:
    End

final:

#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin>>n;
    for(int i=1;;i++){
        if(n/2==1)break;
        if(n%2==0){
            cout<<n<<"/2="<<n/2<<endl;
            n/=2;
        }
        else{
            cout<<n<<"*3+1="<<n*3+1<<endl;
            n=n*3+1;
        }
    }
    cout<<"End";
      return 0;
}

by gaohuashengtx @ 2024-12-22 20:48:16

@ChenHaoQi 75分 3个AC 1个WA 2个TLE


by zxckhj114514 @ 2024-12-22 20:49:10

#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin>>n;
    while(n>1){
        if(n%2==0){
            cout<<n<<"/2="<<n/2<<endl;
            if(n/2==1)break;
            n/=2;
        }
        else{
            cout<<n<<"*3+1="<<n*3+1<<endl;
            n=n*3+1;
        }
    }
    cout<<"End"<<endl;
      return 0;
}

好了


by zxckhj114514 @ 2024-12-22 20:49:57

@gaohuashengtx@pika_@ChenHaoQi

抽象一个帖子这么多人


| 下一页