NowCoder小定律
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的NowCoder小定律的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 11. 日期和时间
- 下一篇: 集成算法中的Bagging