标签:
求素数表:
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 833 Accepted Submission(s):
477
#include<iostream> #include <cstdio> #include<cstring> using namespace std; bool is_prime(int n) { for(int i=2;i*i<=n;i++){ if(n%i==0) return false; } return n!=1; } int main (void) { int n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); if(n==4) { printf("2\n"); continue; } if(is_prime(n)) printf("%d\n",n-1); else printf("0\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4736551.html