社区讨论

这道题题解是不是不太对啊?

B4050[GESP202409 五级] 挑战怪物参与者 5已保存回复 8

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
7 条
当前快照
1 份
快照标识符
@mjnobke4
此快照首次捕获于
2025/12/27 10:20
2 个月前
此快照最后确认于
2025/12/27 10:48
2 个月前
查看原帖
个人认为有些题解错了
CPP
#include<iostream>
using namespace std;
bool is_P(int x){
    if(x<2) return false;
    if(x==2) return true;
    for(int i=2;i*i<x;i++){
        if(x%i==0) return false;
    }
    return true;
}
int att(int x){
    int c=1,h=x;
    for(int i=1;h>=0;i++){
        if(is_P(h)) return i;
        h=h-c;
        c=c*2;
        if(h==0)return i;
    }
    return -1;
}
int main(){
    int t,h;
    cin>>t;
    while(t--){
        cin>>h;
        cout<<att(h)<<"\n";
    }
    return 0;
}

回复

8 条回复,欢迎继续交流。

正在加载回复...