标签:style blog class code c java
1 #include <iostream> 2 3 using namespace std; 4 5 int is_prime(int ); 6 int main() 7 { 8 int x,y,val; 9 while (cin>>x>>y && x||y) 10 { 11 int flag = 1; 12 for (int i=x;i<=y;i++) 13 { 14 val = i*i + i +41; 15 /* flag = flag*is_prime(val);*/ 16 if (!is_prime(val)) 17 { 18 flag = 0; 19 break; 20 } 21 } 22 if (flag) 23 { 24 cout << "OK" << endl; 25 } 26 else 27 { 28 cout << "Sorry" <<endl; 29 } 30 } 31 return 0; 32 } 33 34 int is_prime(int n) // 质数返回1 35 { 36 if (n<=2) 37 { 38 return 0; 39 } 40 for (int i = 2; i*i <=n; i++) 41 { 42 if (n % i ==0) 43 { 44 return 0; 45 } 46 } 47 return 1; 48 }
标签:style blog class code c java
原文地址:http://www.cnblogs.com/lingc/p/3725054.html