NowCoder小定律

题目:https://www.nowcoder.com/pat/2/problem/259

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 const int maxn = 10005;
 7 int f[maxn];
 8 
 9 void db(){
10     memset(f, 0, sizeof(f));
11     f[1] = 1;
12     f[2] = 0;
13     f[3] = 0;
14     for (int i = 3; i < maxn; i++){
15         if (f[i] == 0){
16             int j = i+i;
17             while (j < maxn){
18                 f[j] = 1;
19                 j += i;
20             }
21         }
22     }
23 }
24 
25 int main(){
26     std:ios::sync_with_stdio(false);
27     int x, y;
28     db();
29     while ((cin >> x >> y) && (x||y)){
30         int n;
31         bool ok = true;
32         for (int i = x; i <= y; i++){
33             n = i *i + i + 41;
34             if (f[n] == 1){
35                 ok = false;
36                 break;
37             }
38         }
39         if (ok){
40             cout << "OK" << endl;
41         }
42         else
43             cout << "Sorry" << endl;
44     }
45 //    system("pause");
46     return 0;
47 }
原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/8287827.html