OJ里面总是报错(答案错误50),不知道代码哪里不符合(能够正常运行,且能做出正确答案)
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x,y<=50),判定该表达式的值是否都为素数。
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main()
{
int arr[1000];
int x, y;
while (cin >> x >> y)
{
int n = 0, flag = 0;
if (x == 0 && y == 0)
break;
if (x >= -39 && x <= y && y <= 50)
{
for (int i = x; i <= y; i++)
arr[n++] = i *i + i + 41;
for (int j = 0; j <= (y - x); j++)
{
for (int k = 2; k < sqrt(arr[j]); k++)
{
if (arr[j] % k == 0)
{
flag++;
break;
}
}
}
if (flag == 0)
cout << "OK" << endl;
else
cout << "Sorry" << endl;
}
}
return 0;
}