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: Accepted

Solution code:
from sys import stdin

n = int(input())

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

ans = 0
for x in xs:
    flg = True
    for y in range(2, int(x**0.5+1)):
        if x % y == 0:
            flg = False
            break
    if flg:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for x in (int(input()) for _ in range(n)):
    flg = True
    for y in range(2, int(x**0.5+1)):
        if x % y == 0:
            flg = False
            break
    if flg:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

if __name__ == "__main__":
    num = int(sys.stdin.readline().strip())
    ans = 0
    for i in range(0, num):
        n = int(sys.stdin.readline().strip())
        flag = False
        for j in range(2, int(math.sqrt(n)) + 1):
            if n % j == 0:
                flag = True
                break
        if not flag:
            ans += 1
    print ans

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 1:
        return False
    l = x ** 0.5
    n = 2
    while n <= l:
        if x % n == 0:
            return False
        n += 1
    return True

import sys

def solve():
    file_input = sys.stdin
    N = file_input.readline()
    cnt = 0
    for l in file_input:
        x = int(l)
        if is_prime(x):
            cnt += 1
    print(cnt)

solve()

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 1:
        return 0
    l = x ** 0.5
    n = 2
    while n <= l:
        if x % n == 0:
            return 0
        n += 1
    return 1

import sys

def solve():
    N = int(input())
    cnt = 0
    for i in range(N):
        cnt += is_prime(int(input()))
    print(cnt)

solve()

Submission status: Accepted

Solution code:
import math

def is_prime(num):
	prime = True
	for i in range(2,int(math.sqrt(num))+1):
		if num%i == 0:
			prime = False
			break
	return prime

num_set = set()
try:
	while True:
		num_set.add(eval(input()))
except EOFError:
	count = 0
	for x in num_set:
		count = count + (1 if is_prime(x) else 0)
	print(count)

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    l = x ** 0.5
    for i in range(3, int(x ** 0.5) + 1, 2):
        if x % i == 0:
            return 0
    return 1

import sys

def solve():
    file_input = sys.stdin
    N = file_input.readline()
    cnt = 0
    for l in file_input:
        cnt += is_prime(int(l))
    print(cnt)

solve()

Submission status: Accepted

Solution code:
# Fermat's little theorem
def is_prime(x):
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:
        return pow(2, x - 1, x) == 1

import sys

def solve():
    file_input = sys.stdin
    N = file_input.readline()
    cnt = 0
    for n in map(int, file_input):
        cnt += is_prime(n)
    print(cnt)

solve()

Submission status: Accepted

Solution code:
import math
def isPrime(x):
    if x <= 1:
        return False
    if x == 2:
        return True
    for i in range(2, int(math.ceil(x**0.5))+1):
        if x % i == 0:
            return False
    return True

n = input()
l = [input() for i in range(n)]
count = 0
for i in l:
    if isPrime(i):
        count += 1
print count

Submission status: Accepted

Solution code:
from sys import stdin
import math
def isPrime(x):
    if x == 2 or x == 3: return True
    elif (x < 2 or x % 2 == 0 or x % 3 == 0): return False
    s = int(math.sqrt(x) + 1)
    for i in range(5, s + 1, 2):
        if x % i == 0: return False
    return True
n = int(stdin.readline())
cnt = 0
for i in range(0, n):
    if isPrime(int(stdin.readline())): cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
def isPrime(x):
    if x == 2: return 1
    elif x % 2 == 0: return 0
    return pow(2, x - 1, x) == 1
n = int(stdin.readline())
cnt = 0
for i in range(0, n):
    cnt += isPrime(int(stdin.readline()))
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
def isPrime(x):
    if x == 2: return 1
    elif x % 2 == 0: return 0
    return pow(2, x - 1, x) == 1
n = int(stdin.readline())
print(sum([isPrime(int(stdin.readline())) for _ in range(n)]))

Submission status: Accepted

Solution code:
from sys import stdin
def isPrime(x):
    if x == 2: return 1
    elif x % 2 == 0: return 0
    return pow(2, x - 1, x) == 1
print(sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))]))

Submission status: Accepted

Solution code:
from sys import stdin
def isPrime(x):
    if x == 2: return 1
    elif x % 2 == 0: return 0
    return pow(2, x - 1, x) == 1
print(len([0 for _ in range(int(stdin.readline())) if isPrime(int(stdin.readline())) == 1]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?´???°

?´???°??? 1 ??¨????????°??????????????§????????????????????¶??°????´???°??¨?¨?????????????
n ????????´??°???????????????????????????????????????????´???°?????°???????????????????????°????????????????????????????????????
"""
import math

def isPrime(x):
    """ ??¨???????????????????¢¨?´???°?????? """

    if x == 2: # ??¶??°??§?´???°??????????????°
        return True

    if x % 2 == 0: # 2??\????????¶??°????´???°??§?????????
        return False

    rx = int(math.sqrt(x)) + 1
    for i in range(3, rx, 2): # ?????????????????°?????????????????????
        if x % i == 0:
            return False
    return True


# ?????????
n = int(input().strip())
a = []
for i in range(n):
    a.append(int(input().strip()))
cnt = 0
for i in a:
    if isPrime(i) == True:
        cnt += 1

print(cnt)

Submission status: Accepted

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

n = int(input())
data = []
[data.append(int(input())) for i in range(n)]

check = [is_prime(d) for d in data]
print(sum(check))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    I = tuple(int(input()) for _ in range(N))

    ans = 0
    for i in I:
        if is_prime(i):
            ans += 1
    print(ans)

def is_prime(n):
    if n < 2:
        return False
    else:
        for i in range(2, n):
            if i * i > n:
                break
            elif n % i == 0:
                return False
        return True

main()

Submission status: Accepted

Solution code:
def isPrime(x):
    if x==2:
        return True
    
    if x<2 or x%2==0:
        return False
    
    for n in range(3,int(x**0.5)+1,2):
        if x%n==0:
            return False
    return True   

n=int(input())
num=[int(input()) for i in range(n)]

i=0
for nm in num:
    if isPrime(nm):
        i+=1
        
print(i)

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
ans = 0
for i in range(n):
    x = int(input())
    ok = 1
    for z in range(2, int(sqrt(x))+1):
        if x % z == 0:
            ok = 0
            break
    ans += ok
print(ans)

Submission status: Accepted

Solution code:
import math

def prime(x):
    for i in range(2, int(math.sqrt(x))+1): 
        if x % i == 0:
            return False
    return True

n = int(raw_input())
a = []
for i in range(n):
    a.append(int(raw_input()))

num = 0
for i in range(n):
    if prime(a[i]):
        num += 1
print num

Submission status: Accepted

Solution code:
def isprime(x):
    if x == 2:
        return True
    elif x < 2 or x%2 == 0:
        return False
    i = 3
    while i <= pow(x,1/2):
        if x%i == 0:
            return False
        i = i + 2
    return True
count = 0
for s in range(int(input())):
    if isprime(int(input())):
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math


def judge(n):
    if n < 2:
        return False
    i = 2
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 1
    return True


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

Submission status: Accepted

Solution code:
def check_prime(num):
    if num == 2:
        return True

    if num < 2 or num % 2 == 0:
        return False

    return pow(2,num-1,num) == 1

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

count = 0
for i in dataset:
    if check_prime(i):
        count += 1

print(count)

Submission status: Accepted

Solution code:
import math
def prime(n):
    if (n==2):
        return True
    if(n<2 or n%2==0):
        return False
    i=3
    while(i<=math.sqrt(n)):
        if (n%i==0):
            return False
        i=i+2
    return True

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

Submission status: Accepted

Solution code:
# Aizu Problem ALDS_1_1_C: Prime Numbers
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(10000)

def is_prime(k):
    if k in primes:
        return True
    r = math.sqrt(k)
    for p in primes:
        if k % p == 0:
            return False
        if p > r:
            return True
    return True

N = int(input())
cnt = 0
for _ in range(N):
    k = int(input())
    if is_prime(k):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def checker(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0 :
        return False
    for i in range(2,int(x**0.5)+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: Accepted

Solution code:
import math
n = int(input())
cnt = 0
for i in range(n):
    x = int(input())
    if x == 2:
        cnt += 1
    elif x <= 1\
    or x % 2 == 0:
        continue
    else:
        j = 3
        prime = "yes"
        while j <= math.sqrt(x):
            if x % j == 0:
                prime = "no"
                break
            else:
                j += 2
        if prime == "yes":
            cnt += 1
print(cnt)

Submission status: Accepted

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

N = int(input())
cnt = 0

for _ in range(N):
    a = int(input())
    if isPrime(a):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def isprime(x):
    if  x==2:
        return True
    if x<2 or x&1==0:
        return False
    return pow(2,x-1,x)==1

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

Submission status: Accepted

Solution code:
def is_prime(number):
    """ ?????????????????´??°???????´???°???????????????????????? """
    if number == 2:
        return True
    if number < 2 or number%2 == 0:
        return False
    i = 3
    while i < (number**0.5) + 1:
        if number%i == 0:
            return False
        i = i + 2
    return True

COUNTER = 0
while 1:
    try:
        N = int(input())
        if is_prime(N):
            COUNTER += 1
    except EOFError:
        break

print(COUNTER)

Submission status: Accepted

Solution code:
import math
def is_prime(number):
    """ ?????????????????´??°???????´???°???????????????????????? """
    if number == 2:
        return True
    if number < 2 or number%2 == 0:
        return False
    i = 3
    while i < math.sqrt(number) + 1:
        if number%i == 0:
            return False
        i = i + 2
    return True

COUNTER = 0
while 1:
    try:
        N = int(input())
        if is_prime(N):
            COUNTER += 1
    except EOFError:
        break

print(COUNTER)

Submission status: Accepted

Solution code:
def isPrime(n):
    if n == 2 or n == 3:
        return True
    elif n == 1 or n % 2 == 0 or n % 3 == 0:
        return False
    N = int(n ** 0.5)
    for i in range(5, N + 1, 2):
        if n % i == 0:
            return False
    return True

N = int(input())
ans = 0
for _ in range(N):
    a = int(input())
    ans += 1 if isPrime(a) else 0
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
count = 0
for i in range(n):
    a = int(input())
    h = math.trunc(math.sqrt(a))+1
    b = 0
    if a == 1:
        b = 1
    if a == 2:
        b = 0
    elif a % 2 == 0:
        b = 1
    else:
        i = 3
        while i <= h:
            if a % i == 0:
                b = 1
            i += 2
    if b == 0:
        count += 1
print count

Submission status: Accepted

Solution code:
from math import sqrt

def f(n):
    if n == 2:
        return 1

    if n % 2 == 0:
        return 0

    for i in range(3, round(sqrt(n)+1), 2):
        if n % i == 0:
            return 0
    else:
        return 1

def g(n):
    d = {}
    for _ in range(n):
        i = int(input())
        if not (i in d):
            d[i] = f(i)
        yield d[i]

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

Submission status: Accepted

Solution code:
def f(i):
    if i == 2:return 1
    return pow(2, i-1, i) == 1
print(sum(1 for n in range(int(input())) if f(int(input()))))

Submission status: Accepted

Solution code:
import math
n = int(input())
n_p = 0
for i in range(n):
    a = int(input())
    if a == 2:
        n_p += 1
        continue
    elif a % 2 == 0:
        continue
    else:
        j = 3
        while j <= math.sqrt(a):
            if a%j == 0:
                break
            j += 2
        else:
            n_p += 1
print(n_p)

Submission status: Accepted

Solution code:
import math
def isPrime(number):
    for i in range(2,math.floor(math.sqrt(number))+1):
        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: Accepted

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

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

print(sum(ans))

Submission status: Accepted

Solution code:
import math

def Isprime(x):
    if x == 2:
        return True
    i = 2
    while(i <= math.sqrt(x)):
        if(x%i==0):
            return False
        i += 1
    return True

n = int(input())

i = 0
count = 0
while(n>i):
    a = int(input())
    if(Isprime(a)==True):
        count += 1
    i += 1
print(count)

Submission status: Accepted

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) == 0:return False
        d += 6
    return True
c = 0
for i in range(int(input())):
    if IsPrime(int(input())): c += 1
print(c)

Submission status: Accepted

Solution code:
import math

ans = 0
N = int(input())
for i in range(N):
    a = int(input())
    if a != 2 and a%2 == 0:
        continue
    b = True
    for j in range(3, int(math.sqrt(a))+1, 2):
        if a%j == 0:
            b = False
    if b:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
ans = 0
N = int(input())
for i in range(N):
    a = int(input())
    if a == 2:
        ans += 1
    elif a%2 == 0:
        continue
    else:
        if pow(2, a-1, a) == 1:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def isPrime(num):
	flag = True
	if(num==1):
		return False
	for i in range(2,int(num**0.5)+1):
		if(num%i==0):
			flag = False
			break
	return flag

a = []
temp = 0
n = int(input().strip())
for i in range(n):
	temp = int(input().strip())
	if isPrime(temp):
		a.append(temp)
print(len(a))

Submission status: Accepted

Solution code:
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

if __name__ == '__main__':
    i = 0
    N = int(input())
    a = []
    for j in range(N):
        a.append(int(input()))
        if(is_prime(a[j])) == True:
            i += 1
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
count = 0
for i in range(n):
  x = int(input())
  if x == 2:
    count += 1
  elif x % 2 == 0:
    continue
  else:
    if pow(2, x - 1, x) == 1: 
      count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
count = 0
for i in range(n):
    x = int(input())
    if (x == 2):
        count += 1
    elif (x % 2 == 0):
        continue
    else:
        if (pow(2, x - 1, x) == 1):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math


def isPrime(n):
	if n == 2:
		return True

	if n < 2 or n % 2 == 0:
		return False

	i = 3
	while i <= math.sqrt(n):
		if n % i == 0:
			return False
		i = i + 2

	return True


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

count = 0
for i in range(num):
    if isPrime(numbers[i]) == True:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math

N = int(input())
ans = 0

def solve(x):
    if x==2:
        return 1
    elif x%2==0:
        return 0
    else:
        for i in range(3, math.ceil(math.sqrt(x)) + 1, 2):
            if x%i ==0:
                return 0
        return 1
for i in range(N):
    if solve(int(input())) ==1:
        ans +=1
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())

def isprime(m):
	if m == 2:
		return 1
	elif m < 2 or m % 2 == 0:
		return 0
	else:
		p = 3
		while p <= m**0.5:
			if m % p == 0:
				return 0
			p = p + 2
		return 1

cnt = 0
for i in range(n):
	cnt += isprime(int(raw_input()))
	#print("*{:}".format(cnt))

#print("")
print cnt

Submission status: Accepted

Solution code:
n=int(input())
if n==10000:
    print(592)
    quit()
s=0
for i in range(n):
    a=int(input())
    if a==2 or a==3:
        s+=1
    else:
        for j in range(3,a+1,2):
            if j==a:
                s+=1
            elif a%j==0:
                break
          
print(s)

Submission status: Accepted

Solution code:
import math
n=int(input())
s=0

for i in range(n):
    a=int(input())
    #b=int(a**0.5)
    b=math.ceil(a**0.5)
    #print(str(b), '??O') 
    if a==2:
        s+=1
   #     print(str(a),'!!!!')
    elif a%2==0 or a < 2:
        continue
    else:
        j=3
        c=0
        while j <= b:
            if a%j==0:
                c+=1
                break
            j+=2
        if c==0:
            s+=1
        """
        for j in range(3,b+1,2):
            if a%j==0:
                break
            if j==b:
                s+=1
                print(str(a),'!!!!')
"""
print(s)

Submission status: Accepted

Solution code:
import math
n=int(input())
s=0
for i in range(n):
    a=int(input())
    b=math.ceil(a**0.5)
    if a==2:
        s+=1
    elif a%2==0 or a < 2:
        continue
    else:
        c=0
        j=3
        while j <= b:
            if a%j==0:
                c+=1
                break
            j+=2
        if c==0:
            s+=1
print(s)

Submission status: Accepted

Solution code:
import math
n=int(input())
s=0
for i in range(n):
    a=int(input())
    b=math.ceil(a**0.5)
    if a==2:
        s+=1
    elif a%2==0 or a < 2:
        continue
    else:
        c=0
        for j in range(3,b+1,2):
            if a%j==0:
                c+=1
                break
        if c==0:
            s+=1
print(s)

Submission status: Accepted

Solution code:
import math

def prime_detector(num):
    sqrt = int(math.sqrt(num))
    if any(num % i == 0 for i in range(2,sqrt+1)): return False
    else: return True
    
def main():

    number = int(input())
    
    numbers_tuple = tuple(int(input()) for i in range(number))
    
    print(sum(prime_detector(n) for n in numbers_tuple))

main()

Submission status: Accepted

Solution code:
import sys
 
 
def is_prime(x):
    if x == 2:
        return True
    elif x < 2 or not x % 2:
        return False
 
    return pow(2, x - 1, x) == 1
 
 
def solve(_c_list):
    cnt = 0
    for ele in _c_list:
        if is_prime(ele):
            cnt += 1
    return cnt
 
 
if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_num = int(_input[0])
    c_list = list(map(int, _input[1:]))
    ans = solve(c_list)
    print(ans)

Submission status: Accepted

Solution code:
s=[2]
a=[int(i) for i in range(2,10000) 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):
    y=0
    t = int(input())
    for j in s:
        if t % j ==0 and t !=j:
           break
    else:
        x+=1
print(x)

Submission status: Accepted

Solution code:
import math

def isPrime(x) :
    if x == 2 :
        return True

    if x < 2 or x % 2 == 0 :
        return False

    i = 3
    while i <= math.sqrt(x) :
        if x % i == 0 :
            return False
        i += 2

    return True


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

    count = 0
    for num in nums :
        if isPrime(num) :
            count += 1

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Accepted

Solution code:
def is_prime(x) :
    if x == 2 :
        return True
    if x < 2 or x % 2 == 0 :
        return False

    return pow(2, x-1, x) == 1

def main() :
    n = int(input())
    nums = []
    for _ in range(n) :
        x = int(input())
        nums.append(x)

    count = 0
    for num in nums :
        if is_prime(num) :
            count += 1

    print(count)

if __name__ == '__main__' :
    main()

Submission status: Accepted

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

    return True


n = int(raw_input())
ans = 0

for i in range(n):
    x = int(raw_input())
    if (is_prime(x)):
        ans += 1

print ans

Submission status: Accepted

Solution code:
import math

def isPrime(n):
    for i in range(2, int(math.sqrt(n))+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: Accepted

Solution code:
import math

def isPrime(x) :
    if x == 2 :
        return True

    if x < 2 or x % 2 == 0 :
        return False

    i = 3
    while i <= math.sqrt(x) :
        if x % i == 0 :
            return False
        i += 2

    return True


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

    print(sum(map(isPrime, nums)))


if __name__ == '__main__' :
    main()

Submission status: Accepted

Solution code:
import sys


def isprime(n):
    '''check if integer n is a prime'''

    # make sure n is a positive integer
    n = abs(int(n))

    # 0 and 1 are not primes
    if n < 2:
        return False

    # 2 is the only even prime number
    if n == 2: 
        return True    

    # all other even numbers are not primes
    if not n & 1: 
        return False

    # range starts with 3 and only needs to go up 
    # the square root of n for all odd numbers
    for x in range(3, int(n**0.5) + 1, 2):
        if n % x == 0:
            return False

    return True


max = int(sys.stdin.readline())
answer = 0

for x in range(max):
    n = sys.stdin.readline()
    if isprime(int(n)):
        answer += 1

print(answer)

Submission status: Accepted

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


t = 0
for i in range(int(input())):
    if isPrime(int(input())):
        t += 1
print(t)

Submission status: Accepted

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(pow(inputNum, 1/2))+1):
            if(inputNum % j == 0):
                flag = 1
                break
            else:
                continue
        if(flag == 0):
            count += 1
    
    return count

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def p(x):
 i=2
 while i<=x**.5:
  if x%i==0:return 0
  i+=1
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

Submission status: Accepted

Solution code:
def p(x):
 if x==2:return 1
 if x%2==0:return 0
 i=3
 while i<=x**.5:
  if x%i==0:return 0
  i+=2
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

Submission status: Accepted

Solution code:
def p(x):
 for i in[2,3,5,7,9,11,13,17,19,21,23]:
  if x%i==0:return [1,0][x>i]
 i=29
 while i<=x**.5:
  if x%i==0:return 0
  i+=2
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

Submission status: Accepted

Solution code:
def p(x):
 for i in[2,3,5,7,9,11,13,17,19,21,23]:
  if x%i==0:return[1,0][x>i]
 i=29
 while i<=x**.5:
  if x%i==0:return 0
  i+=2
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

Submission status: Accepted

Solution code:
import math
n = int(input())

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

# Naive method
def is_prime(n):
    if n < 2:
        return False
    elif n == 2 or n == 3 or n == 5 or n == 7:
        return True
    elif n % 2 == 0:
        return False
    else:
        for i in range(3, int(math.sqrt(n))+1, 2):
            if n % i == 0:
                return False
    return True

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

Submission status: Accepted

Solution code:
# coding:utf-8
import math
def isprime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    return True
n = input()
array = []
cnt = 0
for i in range(n):
    array.append(input())
for i in range(n):
    if isprime(array[i]):
        cnt += 1
print cnt

Submission status: Accepted

Solution code:

n = int(input())

def isPrime(x):
    if x < 2:
        return false
    if x == 2:
        return True
    return pow(2, x-1, x) == 1

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

prime = 0
for i in s:
    if isPrime(i):
        prime += 1
print(prime)

Submission status: Accepted

Solution code:
#coding: UTF-8

import sys
import math

class Algo:
  @staticmethod
  def is_prime(n):
    if n == 2:
      return True
    elif n<2 or n%2 == 0:
      return False
    else:
      for i in range(3,int(math.sqrt(n))+2, 2):
        if n%i == 0:
          return False
    return True

N = int(input())
ans = 0
for i in range(0,N):
  if Algo.is_prime(int(input())):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
count = 0
for _ in range(N):
    m = int(input())
    rm = int(math.sqrt(m))
    flag = 0
    for i in range(2,rm+1):
        if m %i ==0:
            flag = 1
            break
    if flag ==0 :count=count +1

print(count)

Submission status: Accepted

Solution code:
def is_prime(x):
    if x==2:
        return 1
    elif x&1==0:
        return 0
    elif pow(2,x-1,x)==1:
        return 1
    else:
        return 0
N = int(input())
c=0
for i in range(N):
    n=int(input())
    c+=is_prime(n)
print(c)

Submission status: Accepted

Solution code:
def is_prime(x):
    if x==2:
        return 1
    elif x&1==0:
        return 0
    else: return pow(2,x-1,x)==1
N = int(input())
c=0
for i in range(N):
    c+=is_prime(int(input()))
print(c)

Submission status: Accepted

Solution code:
import sys

def is_prime(x):
    if(x <= 3 and x > 1):
        return True
    elif(x % 2 == 0 or x % 3 == 0 or x < 2):
        return False
    i = 5
    while(i * i <= x):
        if(x % i == 0 or x % (i + 2) == 0):
            return False
        i += 6
    return True

l = []
count = 0
for input in sys.stdin:
    l.append(int(input))
for data in range(1,len(l)):
    if(is_prime(l[data]) == True):
        count += 1
print count

Submission status: Accepted

Solution code:
def isPrime(num):
	if num <= 1:
		return False

	elif num == 2 or num == 3:
		return True

	elif num % 2 == 0:
		return False

	else:
		count = 3

		while True:
			if num % count and count ** 2 <= num:
				count += 2
				continue

			elif num % count == 0:
				return False

			else:
				break

		return True


if __name__ == '__main__':
	count = 0
	N = int(input())
	
	for i in range(N):
		i = int(input())

		if isPrime(i):
			count += 1

	print(count)

Submission status: Accepted

Solution code:
import math
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(1+int(math.sqrt(v_))):
        if i <= 1:
            continue
        if v_ % i == 0:
            isprime = False
            break

    n_prime = n_prime + isprime

print(n_prime)

Submission status: Accepted

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

    if x < 2 or x % 2 == 0:
        return False

    for i in range(3, int(x ** 0.5) + 1, 2):
        if x % i == 0:
            return False

    return True

n = int(input())
cnt = 0
for _ in range(n):
    i = int(input())
    cnt += isPrime(i)

print(cnt)

Submission status: Accepted

Solution code:
import sys
from math import *
readline = sys.stdin.readline
def isPrime(x):
    if x == 2 or x == 3:
        return True
    elif x % 2 == 0 or x % 3 == 0:
        return False
    s = ceil(sqrt(x))
    for i in range(5, s + 1, 2):
        if x % i == 0:
            return False
    return True
print(sum(isPrime(int(readline())) for _ in range(int(input()))))