【ACM】How many prime numbers
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=2
#include <stdio.h> #include <stdlib.h> #include <math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int f,s,n,i,m; while( scanf( "%d" , &n) != EOF ) { s = 0 ; while( n-- ) { scanf( "%d" , &m ); f = 0; for( i = 2; i <= sqrt( m * 1.0) ; i++ ) { /*统计素数个数 */ if( 0 == m % i ) { /*素数是除了1和本身能整除的数 如果到sqrt(m*1.0) 还不能整除就是素数*/ f = 1 ; break ; } } if ( 0 == f ) s++ ; } printf( "%d\n" , s ); } return 0; }