This question ~ In the past, it was determined that prime was one by one and tried to partition and store the data again. After the question of the Euler's function was obtained last time, it would be faster:
1 prime[0] = prime[1] = 1;2 for(int i = 2; i <maxn; i++)3 {4 if(!prime[i])5 {6 for(int j = i * 2; j < maxn; j += i)7 prime[j] = 1;8 }9 }
The following is the AC code ~~~ Water question ~
1 #include<iostream> 2 #include<memory.h> 3 using namespace std; 4 #define maxn 3000 5 int prime[maxn]; 6 void f() 7 { 8 memset(prime,0,sizeof(prime)); 9 prime[0] = prime[1] = 1;10 for(int i = 2; i <maxn; i++)11 {12 if(!prime[i])13 {14 for(int j = i * 2; j < maxn; j += i)15 prime[j] = 1;16 }17 }18 }19 int main()20 {21 int n,m;22 int f;23 while(cin>>n>>m && (n + m))24 {25 f = 0;26 for(int i = n; i <= m; i++)27 if(prime[i*i+i+41])28 {29 f = 1;30 break;31 }32 if(f)33 cout << "Sorry" << endl;34 else35 cout << "OK" << endl;36 }37 return 0;38 }