#20801: 不知道哪裡有錯球幫忙


chenb1010@gmail.com (POHUA)

學校 : 國立臺北大學
編號 : 98951
來源 : [36.229.66.171]
最後登入時間 :
2021-12-17 16:37:50
b552. 3.找質數 -- 103學年度北二區桃竹苗基區資訊學科能力競賽 | From: [180.176.98.65] | 發表日期 : 2020-03-08 14:47

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;


int main(){
string str;
long long n=0;
vector <int> ans;
while(cin>>str){
ans.clear();
int sum=0,t=0,i=0,j=0,x=0;
n=0;
for(i=0;i<10;i++){
t=0;
n=(n*10+(int(str[i])-48));
for(j=2;j<=sqrt(n)+1;j++){

if(n%j==0 &&n!=2){
t=1;
x++;
break;
}
}

if(t==0 && n!=1 && n!=0){
if(x!=9){
ans.push_back(n);
n=0;
x=0;
}
sum++;
}
}
cout<<sum<<endl;
if(x==9)
cout<<n<<endl;
else
for(int p=0;p<sum;p++)
cout<<ans.at(p)<<endl;
}
return 0;
}

 

 

測試都過 

提交只過第一個測資

 
ZeroJudge Forum