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



Sample input:
5
2
3
4
5
6


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
def isPrime(x):
    if x==2:
        return True
    if x<2 or x%2==0:
        return False
    i=3
    while i*2<=x:
        if x%i==0:
            return False
        i+=2
    return  True

n=input()
ct=0
for i in xrange(n):
    if isPrime(input()):
        ct+=1
print(ct)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
given_list = []
for i in range(n):
    num = int(input())
    given_list.append(num)

given_list.sort()


def prime_list(maximum_num):
    known = []
    num = 2
    while num < maximum_num+1:
        if num == 2: known.append(num)
        for i in known:
            if num % i == 0:
                break
        else:
            known.append(num)


        num += 1
    return known

length = len(given_list)
list_of_primes = prime_list(given_list[length-1])
count = 0
for num in given_list:
    if num in list_of_primes:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
given_list = []
for i in range(n):
    num = int(input())
    given_list.append(num)


def count_prime(given_list):
    count = 0
    for num in given_list:
        for i in range(2,num-1):
            if num % i ==0:
                break
        else:
            count += 1
    return count

print(count_prime(given_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
given_list = []
for i in range(n):
    num = int(input())
    given_list.append(num)

given_list.sort(reverse = True)
known = []
def prime_list(n):
    num = 2
    while num < n+1:
        if num == 2: known.append(2)
        for i in known:
            if num % i == 0:
                break
        else:
            known.append(num)
        num += 1
    return known

def count_prime(given_list):
    count = 0
    for num in given_list:
        if num in known:
            count += 1
        else: pass

    return count

known = prime_list(given_list[0])
result = count_prime(given_list)
print(result)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
given_list = []
for i in range(n):
    num = int(input())
    given_list.append(num)

given_list.sort(reverse = True)
known = [2]
def prime_list(n):
    num = 3
    while num < n+1:
        #if num == 2: known.append(2)
        for i in known:
            if num % i == 0:
                break
        else:
            known.append(num)
        num += 2
    return known

def count_prime(given_list):
    count = 0
    for num in given_list:
        if num in known:
            count += 1
        else: pass

    return count

known = prime_list(given_list[0])
result = count_prime(given_list)
print(result)

Submission status: Time Limit Exceeded

Solution code:
def judge_prime(x):
    A = list(range(2,x+1))
    while A[-1]==x:
        if A[0]==x: return True
        A = list(filter(lambda y: y%A[0]!=0, A))
    return False

if __name__=='__main__':
    N=int(input())
    cnt=0
    for _ in range(N):
        if judge_prime(int(input())): cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

n = int(input())
maximum = 0
given_numbers = dict()
for i in range(n):
    num = int(input())
    if num > maximum:
        maximum = num
    given_numbers[num] = None

def eratosthenes(n):
    root = sqrt(n)
    #print(root)
    nums = []
    for i in range(2,n+1):
        nums.append(i)
    primes = []
    while nums[0] < root:
        for i in nums:
            if i != nums[0] and i % nums[0] == 0:
                nums.remove(i)
        primes.append(nums[0])
        nums.remove(nums[0])
    primes += nums
    return primes

def count_primes(dic, max):
    primes = eratosthenes(max)
    #print(primes)
    count = 0
    for num in dic:
        if num in primes:
            count += 1
    return count

print(count_primes(given_numbers, maximum))

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
A = [int(input()) for x in range(n)]
A_max = max(A)
for i in range(n):
    if A[i] < 2: A[i]=0
    for j in range(2,A[i]):
        if A[i] % j == 0:
            A[i] = 0
print(len([x for x in A if x != 0]))

Submission status: Time Limit Exceeded

Solution code:
import math

def is_prime(num):
    i = 2
    while i < math.sqrt(num):
        if num % i == 0:
            return False
    return True

N = int(input())
cnt = 0
for i in range(0, N):
    n = int(input())
    if (is_prime(n)):
        cnt = cnt + 1
        
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
prime = 0
for i in range(n):
    m = int(input())
    cout = 0
    for j in range(m):
        if m % (j+1) == 0:
            cout += 1
    if cout == 2:
         prime += 1
print(prime)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
counter = 0
for i in range(0, N):
    j = A[i] - 2
    if j == 0 or j == 1:
        counter += 1
    else:
        while j > 1:
            if A[i] % j == 0:
                break
            else:
                j -= 1
        else:
            counter += 1
            
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
counter = 0
for i in range(0, N):
    j = A[i] - 2
    if j == 0 or j == 1:
        counter += 1
    else:
        while j > 1:
            if A[i] % j == 0:
                break
            else:
                j -= 1
        else:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import math

p = 0
n = int(input())

for i in range(n):
    a = int(input())
    
    if a == 2:
        p += 1
    elif a%2 == 0:
        pass
    else:
        d = int(math.sqrt(a))
        i = 3
        while i < d:
            if a%i == 0:
                break
        p += 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp
#?´???°??????
#x????´???°y???2 < y < sqrt(x)??????????????¨??????

from math import sqrt,ceil

def check_prime_number(n):
    sqrt_num = ceil(sqrt(n))
    
    if n == 2:
        return True

    if n < 2:
        return False

    if (n % 2) == 0:
        return False
    
    div = 2
    while div < n:
        if (n % div) == 0:
            return False
        div += 1
    
    return True

def count_prime_numbers(n_list):
    ans = 0
    for n in n_list:
        if check_prime_number(n):
            ans += 1
    return ans

def main():
    num = int(input())
    target_list = [int(input()) for i in range(num)]
    print(count_prime_numbers(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
prime_numbers = [2]
def is_prime(n):
  if n in prime_numbers: return True
  if n > prime_numbers[-1]:
    for i in range(prime_numbers[-1] + 1, n):
      is_prime(i)

  for i in prime_numbers:
    if i ** 2 > n: break
    if n % i == 0: return False
  prime_numbers.append(n)
  return True

N = int(input())
count = 0
for i in range(N):
  x = int(input())
  if is_prime(x): count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math


def is_prime(num):
    for i in range(2, max(num, math.floor(math.sqrt(num)))):
        if num % i == 0:
            return False
    return True


N = int(input())
nums = [int(input()) for _ in range(N)]
ans = len([num for num in nums if is_prime(num)])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def isPrimeNum(x):
	if x == 2:
		return True

	if x % 2 == 0:
		return False
	i = 3
	while i < x:
		if x % i == 0:
			return False
		i += 2
	return True

# input
n = int(raw_input())

if n < 1 or n > 10000:
	exit()

count = 0

for i in range(0, n):
	e = int(raw_input())
	if e < 2 or e > 1000000000:
		exit()
	if isPrimeNum(e):
		count += 1

print count

Submission status: Time Limit Exceeded

Solution code:
def isPrimeNum(x):
	# for speed up
	if x == 2 or x == 3 or x == 5 or x == 7 or x == 11:
		return True
	if x % 2 == 0 or x % 3 == 0 or x % 5 == 0 or x % 7 == 0 or x % 11 == 0:
		return False

	# check by only odd number 
	i = 13
	while i < x:
		if x % i == 0:
			return False
		i += 2
	return True

# input
n = int(raw_input())

if n < 1 or n > 10000:
	exit()

count = 0

for i in range(0, n):
	e = int(raw_input())
	if e < 2 or e > 1000000000:
		exit()
	if isPrimeNum(e):
		count += 1

print count

Submission status: Time Limit Exceeded

Solution code:
def isPrimeNum(x):
	# for speed up
	if x == 2:
		return True
	if x % 2 == 0:
		return False

	# check by only odd number 
	i = 3
	while i <= x / 2 + 1:
		if x % i == 0 or x % (x - i + 2) == 0:
			return False
		i += 2
		
	return True

# input
n = int(raw_input())

if n < 1 or n > 10000:
	exit()

count = 0

for i in range(0, n):
	e = int(raw_input())
	if e < 2 or e > 1000000000:
		exit()
	if isPrimeNum(e):
		count += 1

print count

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
count = 0
while True:
    try:
        n = int(input())
        if n == 2:
            count += 1
        for i in range(2,n):
            if n % i == 0:
                break
            elif i == n - 1:
                count += 1
    except  EOFError:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
count = 0
while True:
    try:
        n = int(input())
        if n == 2 or n == 3:
            count += 1
        if n > 3 and n % 2 != 0:
            for i in range(3,n):
                if n % i == 0:
                    break
                elif i == n - 1:
                    count += 1
    except  EOFError:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
for i in range(n):
    x = int(input())
    counter = 0
    for j in range(x):
        if x % (j+1) == 0:
            counter = counter + 1
    if counter == 2:
        c = c + 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0

for i in range(n):
    data = int(input())
    if data == 2:
        count += 1
    for j in range(2,data):
        if data % j == 0:
            break
        elif j == data - 1:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0

for i in range(n):
    data = int(input())
    data = abs(data)
    if data == 2:
        count += 1
    for j in range(2,data):
        if data % j == 0:
            break
        elif j == data - 1:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
import math
i = input()
count=0

for m in range(int(i)):
    num = int(input())
    arr=[]
    #print(num)
    sq = math.sqrt(num)
    for n in range(1,num):
        if num%n==0:
            arr.append(n)   
    if len(arr)==1:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
def get_prime(m):
    a = [2]+[i for i in range(3,m+1,2)]
    end = int(math.sqrt(m))
    for i in range(3, end, 2):
        if (i in a):
            for j in range(i*2, m, i):
                if (j in a):
                    a.remove(j)
            
    return a
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
primes = get_prime(max(a))
result = 0
for i in range(n):
    if a[i] in primes:
        result+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:

n_input = int(input())

main_count = 0

for i in range(n_input):
  n = int(input())
  dev = 2
  sub_count = 0
  while dev <= n:
    if n % dev == 0:
      sub_count += 1
    dev += 1
  if sub_count == 1:
     main_count += 1

print(main_count)

Submission status: Time Limit Exceeded

Solution code:
import math

def prime(n):
    for i in range(2, int(n/2)+1):
        if  n % i == 0:
            return False
    return True

num_prime = []
k = 0
while True:
    try:
        n = input()
    except:
        break
    if prime(int(n)):
        if not int(n) in num_prime:
            k += 1
            num_prime.append(int(n))

print(k)

Submission status: Time Limit Exceeded

Solution code:
import math
    
def isprime(x):
    p = [2]
    if x == 2:
        return True
    if x == 3:
        return True
    if max(p) < x**0.5:
        for j in range(max(p), math.floor(x**0.5) + 1):
            if all([j % k != 0 for k in p]):
                p.append(j)
    i = 0
    while i <= len(p)-1:
        if p[i] > x**0.5:
            return False
        if x%p[i] == 0:
            return False
        i += 1
    return True


n = int(input())
res = 0
for i in range(n):
    k = int(input())
    if isprime(k):
        res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
answer=0
for i in range(n):
    t=int(input())
    k=2
    numlist=[0 for i in range(t+1)]
    numlist[0]=-1
    numlist[1]=-1


    read=2
    while read<=t**0.5:
        if numlist[read]==0:
            k=1
            while read*(k+1)<=t:
                numlist[read*(k+1)]=-1
                k+=1
        read+=1

    if numlist[-1]==0:
        answer+=1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))

for a in A:
    for i in range(2, a//2+1):
        if a%i == 0:
            n -= 1
            break

print(n)

Submission status: Time Limit Exceeded

Solution code:
max_count = int(input())

count = 0
for i in range(max_count):
	num = int(input())
	f = 1
	for d in range(2, num):
		if num % d == 0:
			f = 0
			break;
	if f == 1:
		count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
max_count = int(input())

count = 0
for i in range(max_count):
	num = int(input())
	if num % 2 != 0:
		f = 1
		for d in range(3, num, 2):
			if num % d == 0:
				f = 0
				break
		if f == 1:
			count += 1
	elif num == 2:
		count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
prime_list = [2,3,5,7,11]
def appendp(num):
    for i in range(prime_list[-1], num+1, 2):
        for j in prime_list:
            if i % j == 0 or i in prime_list:
                break
            if j == prime_list[-1]:
                prime_list.append(i)

def prime_number():
    n = int(input())
    count = 0
    for _ in range(n):
        a = int(input())
        if a > prime_list[-1]:
            appendp(a)
        if a in prime_list:
            count += 1
    print(count)


if __name__ == "__main__":
    prime_number()

Submission status: Time Limit Exceeded

Solution code:
def is_prime(x):

    if x == 2 : return True

    for i in range(2, x):
        if x % i == 0:
            return False

    return True


n = int(input())
res = 0

for _ in range(n):
    x = int(input())
    if is_prime(x): res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    nums = [int(n) for n in stdin]

    primes = list(filter(is_prime, nums))
    print(len(primes))

def is_prime(n):
    if 1 == n:
        return False

    if 2 == n:
        return True

    if 0 == n % 2:
        return False

    for i in range(3, n, 2):
        if 0 == n % i:
            return False

    return True

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
for i in range(n):
    yakusuu = 0
    k = int(input())
    for j in range(1, k+1):
        if k % j == 0:
            yakusuu += 1
        if yakusuu > 2:
            break
    if yakusuu == 2:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def get_prime_list(max_num):
    res = range(2, max_num + 1)
    for i in range(2, max_num/2 + 1):
        res = filter(lambda x: not ((x % i == 0) and (x != i)), res)        
    return res

def is_include(array, num):
    right = len(array) - 1
    left = 0
    while right >= left:
        index = (right + left) / 2
        if array[index] == num:
            return True
        elif array[index] < num:
            left = index + 1
        elif array[index] > num:
            right = index - 1
    return False

if __name__ == "__main__":
    num = int(sys.stdin.readline().strip())
    num_list = [int(sys.stdin.readline().strip()) for i in xrange(0, num)]
    prime_list = sorted(get_prime_list(max(num_list)))
    print len(filter(lambda x: is_include(prime_list, x), num_list))

Submission status: Time Limit Exceeded

Solution code:
def judge(n):
    if n<2:
        return False
    if n==2:
        return True
    if n%2==0:
        return False
    i=3
    while i<n:
        if n%i==0:
            return False
        i+=1
    return True

N=int(input())
count=0
for i in range(N):
    if(judge(int(input()))==True):
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def judge(n):
    if n < 2:
        return False
    if n == 2 or n == 3 or n == 5 or n == 7 or n == 11 or n == 13 or n == 17:
        return True
    if n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n % 7 == 0 or n % 11 == 0 or n % 13 == 0 or n % 17 == 0:
        return False
    i = 23
    while i < n:
        if n % i == 0:
            return False
        i += 1
    return True


N = int(input())
count = 0
for i in range(N):
    if (judge(int(input())) == True):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def judge(n):
    if n < 2:
        return False
    if n == 2 or n == 3 or n == 5 or n == 7 or n == 11 or n == 13 or n == 17:
        return True
    if n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n % 7 == 0 or n % 11 == 0 or n % 13 == 0 or n % 17 == 0:
        return False
    i = 19
    while i < n:
        if n % i == 0:
            return False
        i += 1
    return True


N = int(input())
count = 0
for i in range(N):
    if (judge(int(input())) == True):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def judge(n):
    if n < 2:
        return False
    if n == 2 or n == 3 or n == 5 or n == 7 or n == 11 or n == 13 or n == 17 or n==19 or n==23 or n==29 or n==31 or n==37:
        return True
    if n % 2 == 0 or n % 3 == 0 or n % 5 == 0 or n % 7 == 0 or n % 11 == 0 or n % 13 == 0 or n % 17 == 0 or n%19==0 or n%23==0 or n%29==0 or n%31==0 or n%37==0:
        return False
    i = 19
    while i < n:
        if n % i == 0:
            return False
        i += 1
    return True


N = int(input())
count = 0
for i in range(N):
    if (judge(int(input())) == True):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
cnt_num = int(input())
dataset = [int(input()) for i in range(cnt_num)]

count = 0
for i in dataset:
    if i <= 1:
        continue

    if i == 2:
        count += 1
        continue

    if i == 3:
        count += 1
        continue

    if i % 2 == 0:
        continue

    ng = ''
    for j in range(3,i,2):
        if i % j == 0:
            ng = 'X'
            break

    if ng == '':
        count += 1
        continue

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count=0
for i in range(N):
    n=int(input())
    s=2
    for j in range(n):
        if (n==2):
            count+=1
            break
        tmp=n%s
        if (tmp!=0):
            s+=1
            if (s==n):
                count+=1
                break
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
def division(x,y):
    if y == 0:
        return x
    return  division(y, x%y)

def checker(x):
    for i in range(2,x//2+1):
        v = division(x,i)
        if v > 1 :
            return False
    return True

cnt=0
q=int(input())
for i in range(q):
    o=checker(int(input()))
    if o:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def division(x,y):
    if y == 0:
        return x
    return  division(y, x%y)

def checker(x):
    if x < 2:
        return False
    for i in range(2,x//2+1):
        v = division(x,i)
        if v > 1 :
            return False
    return True

cnt=0
q=int(input())
for i in range(q):
    o=checker(int(input()))
    if o:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def checker(x):
    for i in range(2,x//2+1):
        if x % i == 0:
            return False
    return True

cnt = 0
q = int(input())
for _ in range(q):
    v=int(input())
    if checker(v):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def g(n):
    for _ in range(n):
        t = int(input())

        if t == 2 or t == 3:
            yield 1
        else:
            for i in range(2, t // 2 + 1):
                if t % i == 0:
                    yield 0
                    break
            else:
                yield 1

n = int(input())
print(sum(g(n)))

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

@lru_cache(maxsize=None)
def g(n):
    for _ in range(n):
        t = int(input())

        if t == 2 or t == 3:
            yield 1
        else:
            for i in range(2, t // 2 + 1):
                if t % i == 0:
                    yield 0
                    break
            else:
                yield 1

n = int(input())
print(sum(g(n)))

Submission status: Time Limit Exceeded

Solution code:
def isPrime(number):
    for i in range(2,number):
        if number%(i)==0:
            return False
    return True
N=int(input())
numbers=[]
for i in range(N):
    numbers.append(int(input()))
    pass
count=0
for number in numbers:
    if isPrime(number):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
numbers = [int(input()) for i in range(N)]
ans = []

def check_prime(n):
    for i in range(2, n):
        if n % i == 0:
            return 0
    else:
        return 1
    
for n in numbers:
    ans.append(check_prime(n))

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
def IsPrime(n):
    '''

    :param n:??£??´??°
    :return: ?´???°?????????True, ????????????????????°?????????False
    ???????????§???????´???°??? 6k-1????????? 6k+1??§??¨?????????????????????k?????£??´??°
    '''
    if n == 2 or n == 3 or n== 5: return True
    if n == 1 or n%2 == 0 or n%3 == 0:return False
    d, l = 5, int(n**(1/2))
    while d <= l:
        if n%d == 0 or n%(d+2):return False
    return True
c = 0
for i in range(int(input())):
    if IsPrime(int(input())): c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0

def prime(x):
    if x<2:
        return 0
    elif x %2 == 0:
        if x ==2:
            return 1
        else :
            return 0
    else:
        i = 3
        while i**2<= x:
            if x % i== 0:
                return 0
        return 1

for i in range(N):
    x = int(input())
    if prime(x) ==1:
        ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(int(input()))

    A.sort(reverse = True)
    Pn = []   #Prime numbers
    for x in range(1, A[0] + 1):
        c1 = 0
        for y in range(1, x):
            if x % y == 0:
                c1 += 1
                if c1 > 1:
                    break
        if c1 == 1:
            Pn.append(x)

    c2 = 0
    for x in range(n):
        if A[x] in Pn:
            c2 += 1
    print(c2)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(int(input()))

    A.sort(reverse = True)
    Pn = []   #Prime numbers
    for x in range(1, A[0] + 1):
        if x > 2 and x % 2 == 0:
            pass
        else:
            c1 = 0
            for y in range(1, x):
                if x % y == 0:
                    c1 += 1
                    if c1 > 1:
                        break
            if c1 == 1:
                Pn.append(x)

    c2 = 0
    for x in range(n):
        if A[x] in Pn:
            c2 += 1
    print(c2)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    
    A = []
    for _ in range(n):
        A.append(int(input()))
    mx = max(A)

    Pn = [2]   #Prime numbers
    for x in range(3, mx + 1, 2):
        c1 = 0
        for y in range(len(Pn)):
            if x % Pn[y] == 0:
                c1 = 1
                break
        if c1 == 0:
            Pn.append(x)

    c2 = 0
    for a in A:
        if a in Pn:
            c2 += 1

    print(c2)
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=0
for i in range(n):
    a=int(input())
    c=0
    for j in range(2,a+1):
        if a%j==0:
            break
        c+=1
    if c==a-2:
       s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=0
for i in range(n):
    a=int(input())
    c=0
    if a==2:
        s+=1
    else:
        for j in range(2,a,1):
     #  i print(j)
            if a%j==0:
                break
            else:
                if j==a-1:
                    s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=0
for i in range(n):
    a=int(input())
 #   print(str(a),'DAYO')
    if a==2 or a==3:
        s+=1
    else:
        for j in range(3,a+1,2):
          #  print(str(i), str(j)+'PP')
            if j==a:
                s+=1
            elif a%j==0:
                break

print(s)

Submission status: Time Limit Exceeded

Solution code:
s=[2]
a=[int(i) for i in range(2,100000000) if pow(2 ,int(i)-1, int(i)) ==1]

while a!=[]:
    t=a[0]
    a=[i for i in a if i % t !=0]
    s.append(t)
 
n=int(input())
x=0
for i  in range(n):
    if int(input()) in s:
        x+=1
print(x)

Submission status: Time Limit Exceeded

Solution code:
def main() :
    n = int(input())
    nums = []
    for i in range(0, n) :
        x = int(input())
        nums.append(x)

    count = 0
    for i in nums :
        judge = 0
        for j in range(2, i) :
            if (i % j) != 0 :
                judge += 0
            else :
                judge += 1

        if judge == 0 :
            count += 1

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
def isPrime(n):
    for i in range(2, int(n/2)+1):
        if n % i == 0:
            return False
    return True

N = int(input())
nums = [int(input()) for i in range(N)]
print(sum([isPrime(n) for n in nums]))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    print(IsPrime(N))

def IsPrime(N):
    count = 0
    for i in range(N):
        inputNum = int(input())
        if(inputNum == 2):
            count += 1
            continue
        elif(inputNum % 2 == 0):
            continue

        flag = 0
        for j in range(3, int(inputNum/2), 2):
            if(inputNum % j == 0):
                flag = 1
                break
            else:
                continue
        if(flag == 0):
            count += 1
    
    return count

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def p(n):
 for i in range(2,n):
  if n%i==0:return 0
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

A = [0] * n
for i in range(n):
    A[i] = int(input())

def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, n, 2):
        if n % i == 0:
            return False
    return True

print(len([x for x in A if is_prime(x)]))

Submission status: Time Limit Exceeded

Solution code:
c = 0
def is_prime(n):
    for i in range(2, int(n**1/2)+1):
        if not(n % i):
            return False
    return True
for _ in range(int(input())):
    if is_prime(int(input())):
        c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = [int(input()) for i in range(N)]
c=0
for i in range(N):
    x=A[i]
    if x < 2: continue
    if x==2 or x==3 or x==5:c+=1
    if x%2==0 or x%3==0 or x%5==0: continue

    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: continue
        prime += step
        step = 6 - step
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys

def is_prime(x,y):
    while(y < x):
        if(x % y == 0):
            return 0
        y += 2
    return 1

a = ""
l = []
count = 0
for input in sys.stdin:
    a += input
l = sorted(set(a.split()))
for input in l:
    if(int(input) > 2 and int(input) % 2 != 0 and is_prime(int(input),3)):
        count += 1
    elif(int(input) == 2):
        count += 1
print count

Submission status: Time Limit Exceeded

Solution code:
import sys

def is_prime(x,y):
    while(y < x):
        if(x % y == 0):
            return 0
        y += 2
    return 1

a = ""
l = []
count = 0
for input in sys.stdin:
    a += input
l = (a.split())
b = int(l[0])
l = sorted(set(l[1:]))
for i in l:
    if(int(i) == 2):
        count += 1
    elif(int(i) > 2 and int(i) % 2 != 0 and is_prime(int(i),3) == 1):
        count += 1
print count

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = []

for _ in range(n):
    v.append(int(input()))

n_prime = 0
for v_ in v:
    isprime = True

    if v_ <= 1:
        continue

    for i in range(v_):
        if i <= 1:
            continue
        if v_ % i == 0:
            isprime = False
            break

    n_prime = n_prime + isprime

print(n_prime)

Submission status: Time Limit Exceeded

Solution code:
def primes(n):
    primes = [2]
    if n < 2:
        return []
    
    for i in range(3, n + 1, 2):
        isPrime = True
        for prime in primes:
            if i % prime == 0:
                isPrime = False
                break
        if isPrime:
            primes.append(i)
    
    return primes

n = int(input())
l = [int(input()) for _ in range(n)]

print(len([x for x in l if x in primes(max(l))]))

Submission status: Time Limit Exceeded

Solution code:
def primesUpTo(n):
    primes = [2]
    if n < 2:
        return []

    for i in range(3, n + 1, 2):
        isPrime = True
        for prime in primes:
            if prime ** 2 > n:
                break
            if i % prime == 0:
                isPrime = False
                break
        if isPrime:
            primes.append(i)

    return primes

n = int(input())
l = [int(input()) for _ in range(n)]
primes = primesUpTo(max(l))

print(len([x for x in l if x in primes]))