社区讨论
10分求改代码必关注
B4050[GESP202409 五级] 挑战怪物参与者 4已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mlqm8rnp
- 此快照首次捕获于
- 2026/02/17 21:05 前天
- 此快照最后确认于
- 2026/02/18 20:24 16 小时前
球球了,帮帮这位正在勤奋做假期作业的小学生吧!
CPP#include<bits/stdc++.h>
using namespace std;
bool iszhishu(int a){
if(a==1||a==4){
return 0;
}else if(a==2||a==3){
return 1;
}else if(a%6!=1&&a%6!=5){
return 0;
}
for(int i=5;i<=sqrt(a);i+=6){
if(a%i==0||a%(i+2)==0){
return 0;
}
}
return 1;
}
int main() {
int t,h;
cin>>t;
for(int i=1;i<=t;i++){
int ans=0;
int j=1;
bool dj=0;
cin>>h;
while(h>0){
if(iszhishu(h)&&dj==0){
//cout<<"mf"<<' '<<h<<endl;
h=0;
ans++;
continue;
}
h-=(2*j-1);
//cout<<"wl"<<' '<<2*j-1<<endl;
ans++;
j++;
}
if(h<0){
cout<<-1<<endl;
}else{
cout<<ans<<endl;
}
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...