![]() |
#2
rjsp2013-08-07 13:26
|
素数判定
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56842 Accepted Submission(s): 19531
Problem Description
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
Input
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int x,y,j,k;
while(cin>>x>>y)
{
if(x==0 && y==0)
break;
for(x; x<=y ;++x)
{ k=1;
j=x*x+x+41;
for(int i=2;i<=(sqrt(j)); i++)
{
if(j%i==0)
{
k=0;
break;
}
}
if(k==0)
break;
}
if(k==0)
cout<<"Sorry"<<endl;
else
cout<<"OK"<<endl;
}
return 0;
}
这是什么错误#include <math.h>
using namespace std;
int main()
{
int x,y,j,k;
while(cin>>x>>y)
{
if(x==0 && y==0)
break;
for(x; x<=y ;++x)
{ k=1;
j=x*x+x+41;
for(int i=2;i<=(sqrt(j)); i++)
{
if(j%i==0)
{
k=0;
break;
}
}
if(k==0)
break;
}
if(k==0)
cout<<"Sorry"<<endl;
else
cout<<"OK"<<endl;
}
return 0;
}
View Compilation Error
0_0_8856365_32655.cpp
0_0_8856365_32655.cpp(15) : error C2668: “sqrt” : 对重载函数的调用不明确
\include\math.h(626): 可能是“long double sqrt(long double)”
\include\math.h(578): 或 “float sqrt(float)”
\include\math.h(200): 或 “double sqrt(double)”
试图匹配参数列表“(int)”时