水的不行不行的一道题 也是自己做的第一道题 纪念下

1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 int main() 5 { 6 int n, sum, k, count; 7 int z[2002]; 8 memset( z , 0 , sizeof(z)); 9 while( scanf( "%d" , &n) != EOF&&n>=1&&n<=1000 ) 10 { 11 sum = 0; 12 k = 0; 13 14 for( int i = 0; i < n; i++) 15 { 16 17 scanf( "%d", &z[i]); 18 } 19 20 21 for( int i = 0; i < n; i++ ) 22 { 23 count = 0; 24 int h = 0; 25 26 for( int j = 1; j <= z[i]; j++) 27 { 28 29 if( z[i] % j == 0) count++; 30 if( count > 2) break; 31 32 } 33 if( count <=2 ) 34 { 35 sum+=z[i]; 36 } 37 } 38 39 printf( "%d ", sum); 40 } 41 return 0; 42 }
本来想用辗转相除求公约数 最后想了下 试试普通方法 有点麻烦了