http://acm.hdu.edu.cn/showproblem.php?pid=1286php
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8694 Accepted Submission(s): 4592
html
分析:編程
題目要求找出小於n 的全部的與n互素的整數(包括1 不包括n)。測試
篩法求素數orzspa
AC代碼:code
1 #include<stdio.h> 2 #include<string.h> 3 int judge[40000]; 4 int main() 5 { 6 int n, m; 7 int ans; 8 scanf("%d", &n); 9 while(n--) 10 { 11 int cnt = 0; 12 scanf("%d", &m); 13 memset(judge, 0, sizeof(judge)); 14 for(int i = 2; i <= m / 2; i++) 15 { 16 if(m%i == 0) 17 { 18 judge[i] = 1; 19 for(int j = i; j <= m; j+=i) 20 judge[j] = 1; 21 } 22 } 23 for(int i = 2; i < m; i++){ 24 if(judge[i] == 0){ 25 cnt++; 26 } 27 } 28 printf("%d\n", cnt + 1); 29 } 30 31 return 0; 32 }