c++ hdu 2012一直显示wrong answer 问问大神们错在哪里啦
#include<iostream>#include<cmath>usingnamespacestd;boolisSushu(intn){if(n==2||n==3||n...
#include <iostream>
#include<cmath>
using namespace std;
bool isSushu(int n){
if(n==2||n==3||n==5||n==7)
return true;
else{
for(int i=2;i<n/2+1;i++){
if(n%i==0)
return false;
}
return true;
}
}
int main() {
int x,y;
while(cin>>x>>y){
int count=0;
if(x==0&&y==0)
break;
else if(x>y){
int temp=x;
x=y;
y=temp;
}
for(int i=x;i<=y;i++){
int a=pow(i,2)+i+41;
if(isSushu(a));
count++;
}
if(count==(y-x+1))
cout<<"OK"<<endl;
else
cout<<"Sorry"<<endl;
}
return 0;
} 展开
#include<cmath>
using namespace std;
bool isSushu(int n){
if(n==2||n==3||n==5||n==7)
return true;
else{
for(int i=2;i<n/2+1;i++){
if(n%i==0)
return false;
}
return true;
}
}
int main() {
int x,y;
while(cin>>x>>y){
int count=0;
if(x==0&&y==0)
break;
else if(x>y){
int temp=x;
x=y;
y=temp;
}
for(int i=x;i<=y;i++){
int a=pow(i,2)+i+41;
if(isSushu(a));
count++;
}
if(count==(y-x+1))
cout<<"OK"<<endl;
else
cout<<"Sorry"<<endl;
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询