Problem:
Prime Numbers

A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.

Write a program which reads a list of N integers and prints the number of prime numbers in the list.

Input

The first line contains an integer N, the number of elements in the list.

N numbers are given in the following lines.

Output

Print the number of prime numbers in the given list.

Constraints

1 ≤ N ≤ 10000

2 ≤ an element of the list ≤ 108

Sample Input 1

5
2
3
4
5
6

Sample Output 1

3

Sample Input 2

11
7
8
9
10
11
12
13
14
15
16
17

Sample Output 2

4

Solution in C (judge verdict: Memory Limit Exceeded)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <time.h>

#define NOCHK 0
#define PRIME 1
#define NOTPRIME 2

static clock_t start_time,end_time;
void clock_start(){
	start_time = clock();
}
void clock_end(char *msg){
	end_time = clock();
	printf("[%s]%ld\n",msg,(end_time-start_time));
}

int main(int argc, char** argv){
	int n,data,*data_list;
	int count;
	int max_data;
	int i,j;
	char *prime_map;

	// Input n
	scanf("%d",&n);
	data_list = malloc(sizeof(int)*n);
	max_data = 0;
	for(i=0;i<n;i++){
		scanf("%d",&data);
		if( data > max_data ){
			max_data = data;
		}
		data_list[i] = data;
	}
	
	// Create Prime Map
//	clock_start();
	prime_map = malloc(sizeof(char)*(max_data+1));
	memset(prime_map,NOCHK,sizeof(char)*(max_data+1));
	for(i=2;i<=max_data;i++){
		if( prime_map[i] == NOCHK ){
			prime_map[i] = PRIME;
			for(j=i*2;j<=max_data;j+=i){
				prime_map[j] = NOTPRIME;
			}
		}
	}
//	clock_end("Create Prime Map");

	// Check Prime Count
//	clock_start();
	count = 0;
	for(i=0;i<n;i++){
		if( prime_map[data_list[i]] == PRIME ){
			count++;
		}
	}
//	clock_end("Check Prime Count");

	// Output
	printf("%d\n",count);

	return 0;
}