标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7017 Accepted Submission(s): 2336
1 #include <iostream> 2 #include <cmath> 3 #include <stdio.h> 4 #include <cstring> 5 6 using namespace std; 7 8 typedef long long LL; 9 LL power(LL m,LL n,LL k) 10 { 11 int b = 1; 12 while (n > 0) 13 { 14 if (n & 1) 15 b = (b*m)%k; 16 n = n >> 1 ; 17 m = (m*m)%k; 18 } 19 return b; 20 } 21 bool judge(LL n) 22 { 23 LL i; 24 if (n<=3) return true; 25 for (i=2;i<=ceil(sqrt(n))+1;i++) 26 if (n %i==0) return false; 27 return true; 28 } 29 30 int main() 31 { 32 LL i,n,x; 33 34 while (scanf("%I64d",&n)!=EOF) 35 { LL ans=0; 36 for (i=1;i<=n;i++) 37 { 38 scanf("%I64d",&x); 39 if ((power(61,x-1,x)==1)&&(power(11,x-1,x)==1)&&(power(31,x-1,x)==1) 40 &&(power(97,x-1,x)==1)) 41 ans++; 42 } 43 printf("%I64d\n",ans); 44 } 45 return 0; 46 } 47 48 49 50
hdu 2138 How many prime numbers
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4295349.html