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:
# ALDS_1_C.
from math import sqrt, floor

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def get_prime():
    P = []
    P.append(2); P.append(3); P.append(5); P.append(7)
    # まず100までの素数を作って、それから10000まで行く。
    # 100までの合成数は必ず2, 3, 5, 7のどれかで割れる。
    for n in range(8, 101):
        is_prime = True
        for i in range(4):
            if n % P[i] == 0: is_prime = False; break
        if is_prime: P.append(n)
    for n in range(101, 10001):
        is_prime = True
        limit = floor(sqrt(n))
        for i in range(len(P)):
            if n % P[i] == 0: is_prime = False; break
            if P[i] > limit: break
        if is_prime: P.append(n)
    return P

def main():
    # 10000までの素数のリスト作って、
    # 平方根までの素数で割っていった方が早い。多分。
    primes = get_prime()
    n = int(input())
    data = []
    for i in range(n): data.append(int(input()))
    count = 0
    for i in range(n):
        # 1と2だけ特別扱いする。
        if data[i] == 1: continue
        if data[i] == 2: count += 1; continue
        # 残りの数は普通に判定する。
        limit = floor(sqrt(data[i]))
        is_prime = True
        for p in primes:
            if data[i] % p == 0: is_prime = False; break
            if p > limit: break
        if is_prime: count += 1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = []

count = 0
for i in range(N):
    x=int(input())
    if x == 2:
        count+=1
    else:
        if pow(2, x-1,x ) == 1:
            count+=1
        else:
            pass

print(count)

Submission status: Accepted

Solution code:
import math


def count_number_of_prime_number(v):
    ans = 0
    for x in v:
        if is_prime(x):
            ans += 1
    return ans


def is_prime(x):
    for n in range(2, math.floor(math.sqrt(x)) + 1):
        if x % n == 0:
            return False
    return True


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

print(count_number_of_prime_number(v))

Submission status: Accepted

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

cnt = 0
for i in range(int(input())):
    n = int(input())
    if n == 2:
        cnt += 1
        continue
    elif n % 2 == 0: continue
    judge = prime()
    if judge == True:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    inputs = list(map(int, [stdinput() for _ in range(n)]))

    primes = 0
    for a in inputs:
        if is_prime(a, None):
            primes += 1
    print(primes)

def is_prime(a, primes):
    # Search for num below a**0.5,
    # as when A can be devided by number > a**0.5,
    # it means existing number < a**0.5 also can devide A.
    for p in range(2, int(a ** 0.5)  + 1):
        if a % p == 0:
            return False
    return True

if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = int(input())
ans = 0
for i in range(n):
    ans += is_prime(int(input()))
print(ans)

Submission status: Accepted

Solution code:
def eratos(n):
	is_prime = [True for i in range(n+1)]
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, n+1):
		if i * i > n:
			break
		for j in range(i*i, n+1, i):
			is_prime[j] = False
	return is_prime

is_prime = eratos(10000)
primes = []
for i in range(10001):
    if is_prime[i] is True:
        primes.append(i)

n = int(input())
ans = 0
for _ in range(n):
    x = int(input())
    if x <= 10000:
        if is_prime[x] is True:
            ans += 1
    else:
        ok = True
        for i in primes:
            if i * i > x:
                break
            if x % i == 0:
                ok = False
                break
        if ok is True:
            ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

def is_prime(num):
	if num <= 1: return False
	if num == 2: return True
	if num % 2 == 0: return False
	i = 3
	while i <= num**0.5:
		if num % i == 0: return False
		i += 2
	return True

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

Submission status: Accepted

Solution code:
import math
n = int(input())
c = 0
for x in range(n):
    a = int(input())
    for b in range(2, int(math.sqrt(a))+1):
        if a % b == 0:
            break
    else:
        c += 1
print(c)

Submission status: Accepted

Solution code:
def is_prime(num):
	if num <= 1: return False
	if num == 2: return True
	if num % 2 == 0: return False
	i = 3
	while i <= num**0.5:
		if num % i == 0: return False
		i += 2
	return True
	
n = int(input())
cnt = 0
for i in range(n):
	if is_prime(int(input())):
		cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math


def isPrime(n):
    if n <= 2:
        return n == 2
    if (n % 2 == 0):
        return False
    for i in range(3, int(math.sqrt(n)) + 2, 2):
        if n % i == 0:
            return False
    return True


N = int(input())
print(len(list(filter(isPrime, [int(input()) for i in range(N)]))))

Submission status: Accepted

Solution code:
import math


def isPrime(n):
    if n <= 2:
        return n == 2
    if (n % 2 == 0):
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True


N = int(input())
print(len(list(filter(isPrime, [int(input()) for i in range(N)]))))

Submission status: Accepted

Solution code:
import math

def isPrime(n):
    if n <= 2:
        return n == 2
    if (n % 2 == 0):
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True

N = int(input())
print(len(list(filter(isPrime, [int(input()) for i in range(N)]))))

Submission status: Accepted

Solution code:
import math

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

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

N = input()
N = int(N)
l = [input() for i in range(N)]
a = 0
for i in range(0,len(l)):
    if is_prime(int(l[i])) == True:
         a += 1
print(a)

Submission status: Accepted

Solution code:
import math

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

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

N = input()
N = int(N)
l = [int(input()) for i in range(N)]
a = 0
for i in range(0,len(l)):
    if is_prime(l[i]) == True:
         a += 1
print(a)

Submission status: Accepted

Solution code:
def is_prime(a):
    if a == 1:
        return False
    for i in range(2, a):
        if a % i == 0:
            return False
        if i * i > a:
            break
    return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    for i in range(2, math.ceil(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def run():
    n = int(input())
    n_prime = 0
    for i in range(n):
        if is_prime(int(input())):
            n_prime += 1
    print(n_prime)

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
# Prime Numbers

n = int(input())

def isPrime(a):
    # print('a = ' + str(a))
    if a == 2:
        return True
    elif a < 2 or a % 2 == 0:
        return False
    else:
        i = 3
        j = a ** 0.5
        while i <= j:
            if a % i == 0:
                return False
            i += 2
        return True

primeCount = 0
for i in range(n):
    a = int(input())
    if isPrime(a) == True:
        # print(str(a) + ' は素数')
        primeCount += 1

print(primeCount)

Submission status: Accepted

Solution code:
n = int(input())
mlist = []
plist = [2]
for i in range(3,10000):
    count = 0
    for k in plist:
        if (i%k != 0):
            count += 1
        else:
            break
    if (count == len(plist)):
        plist.append(i)
def check(m):
    for p in plist:
        if (m <= p):
            return True
        if m%p == 0:
            return False
    return True
count = 0
for i in range(n):
    m = int(input())
    if check(m):
        count += 1
        
print(count)

Submission status: Accepted

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

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

print(sum(1 for x in xs if isprime(x)))

Submission status: Accepted

Solution code:
class PrimeChecker:

    def __init__(self):
        self.primes = [2,3]

    def isPrime(self, n):
        if n in self.primes:
            return True
        else:
            for i in self.primes:
                if n % i == 0:
                    return False

        i = 5
        w = 2

        while i * i <= n:
            if n % i == 0:
                return False

            i += w
            w = 6 - w

        self.primes.append(n)

        return True

primeChecker = PrimeChecker()
count = 0
N = int(input())
for _ in range(N):
    if primeChecker.isPrime((int(input()))):
        count += 1
print(count)

Submission status: Accepted

Solution code:
class PrimeChecker:
 
    def __init__(self):
        self.primes = [2,3,5]
 
    def isPrime(self, n):
        if n in self.primes:
            return True
        elif n < self.primes[-1]:
            return False
        else:
            for i in self.primes:
                if n % i == 0:
                    return False
 
        i = self.primes[-1]
        w = 2 if i % 6 == 5 else 4
 
        while i * i <= n:
            if self.isPrime(i):
                self.primes.append(i) 
                if n % i == 0:
                    return False
 
            i += w
            w = 6 - w
 
        return True
 
primeChecker = PrimeChecker()
count = 0
N = int(input())
for _ in range(N):
    if primeChecker.isPrime((int(input()))):
        count += 1
print(count)

Submission status: Accepted

Solution code:
f=lambda x: 1 if x==2 or x==3 or (not x<2 and not x&1==0 and pow(2,x-1,x)==1) else 0
print(sum(f(int(input())) for _ in range(int(input()))))

Submission status: Accepted

Solution code:
import math

def main():
    N = input()
    n = [input() for x in range(N)]
    c = 0

    for i in range(N):
        if prime(n[i]):
            c += 1

    print(c)

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

main()

Submission status: Accepted

Solution code:
def get_primes(n):
    if n < 10: return [2,3,5,7]
    x = [0,0]+[i for i in range(2,n+1)]
    for e in get_primes(int(n**0.5+1)):
        for j in range(e*2, n+1,e):
            x[j] = 0
    return filter(None, x)

PRIMES = get_primes(10000)
n = int(input())
c = 0
for i in range(n):
    p = int(input())
    f = 1
    for e in PRIMES:
        if e >= p:
            break
        if p % e == 0:
            f = 0
            break
    c += f
print c

Submission status: Accepted

Solution code:
def get_primes(n):
    x = [0,0]+[i for i in range(2,n+1)]
    for i in range(int(n**0.5+1)):
        e = x[i]
        if e !=0:
            for j in range(e*2, n+1,e):
                x[j] = 0
    return filter(None, x)

PRIMES = get_primes(10000)
n = int(input())
c = 0
for i in range(n):
    p = int(input())
    f = 1
    for e in PRIMES:
        if e >= p:
            break
        if p % e == 0:
            f = 0
            break
    c += f
print c

Submission status: Accepted

Solution code:
import random
def is_prime(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    for i in xrange(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

n=input()
ans=0
for i in range(n):
    p=input()
    if is_prime(p):
        ans+=1
print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from math import sqrt
n = int(stdin.readline())
cnt = 0
for _ in range(n):
    v = int(stdin.readline())
    if v == 2:
        cnt += 1
    elif v % 2 == 1:
        for i in xrange(3, int(sqrt(v))+1, 2):
            if v % i == 0:
                break
        else:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
cnt=0
#sute=0
N=int(raw_input())
for j in range(N):
    x=int(raw_input())
    if x<2: pass
#    elif x==2 or x==3 or x==5 or x==7 or x==11: cnt+=1
    elif x==2: cnt+=1
    elif x%2==1:
        for i in xrange(3, int(x**0.5)+1, 2):
            if x%i==0:
                break
        else:
            cnt+=1
print cnt

Submission status: Accepted

Solution code:
n = input()
s = 0
while n > 0:
	n -= 1
	a = input()
	if a == 1:
		pass
	elif a == 2:
		s += 1
	elif (a%2 == 1):
		for i in xrange(3, (int(a**0.5)+1), 2):
			if a%i==0:
				break	
		else:
			s += 1		
print s

Submission status: Accepted

Solution code:
def main():
    N = int(raw_input())
    s = [int(raw_input()) for x in range(N)]
    count = 0
    for i in s:
        if is_prime(i):
            count +=1
    print count
    
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

main()

Submission status: Accepted

Solution code:
import math
def prime2(x):
    if x == 2: return True
    else:
        for s in stock:
            if x % s == 0: return False
        for j in xrange(3,int(math.sqrt(x))+1,2):
            if x % j == 0: return False
        else:
            stock.append(x)
            return True 
n = input()
count = 0
stock = [2]
for i in xrange(n):
    if prime2(input()): count += 1
print count

Submission status: Accepted

Solution code:
import math
def prime(x):
    if x == 2: return True
    elif x % 2 == 0: return False
    else:
        for j in xrange(3,int(math.sqrt(x))+1,2):
            if x % j == 0: return False
        else:
            return True 
n = input()
count = 0
for i in xrange(n):
    if prime(input()): count += 1
print count

Submission status: Accepted

Solution code:
def isPrime(p):
	if p == 2: return 1
	if p < 2 or p&1 == 0: return 0
	return 1 if pow(2,p-1,p) == 1 else 0
	
n = int(raw_input())
print sum(isPrime(int(raw_input())) for i in range(n))

Submission status: Accepted

Solution code:
import math

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

if __name__ == "__main__":
    import sys
    N = int(sys.stdin.readline().strip())
    ret = 0
    for i in range(N):
        if isPrime(int(sys.stdin.readline().strip())):
            ret += 1
    print ret

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import random

def miller_rabin_test(n,k): #n>3,odd number
    d = n-1
    r = 0
    while True:
        if d%2 == 0:
            r += 1
            d //= 2
        else:
            break
    
    for i in range(k):
        a = random.randint(2,n-2)
        x = pow(a,d,n)# same as (a**d)%n  'pow' runs fast if n is large
        if x == 1 or x == n-1:
            continue
        flag = False
        for j in range(r-1):
            x = pow(x,2,n)# same as (x**2)%n
            if x == n-1:
                flag = True
                break
            if x == 1:
                break
        if flag:
            continue
        else:
            return False
        
    return True

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

count = 0
for i in range(n):
    if a[i] == 2 or a[i] == 3:
        count += 1
        continue
    if a[i] <= 3 or a[i]%2==0:
        continue
    if miller_rabin_test(a[i],100):
        count += 1
print(count)

Submission status: Accepted

Solution code:
times = int(input())
count = 0
import math

def isPrime(x):
    d = 3
    if x == 2:
        return True
    if x%2 == 0:
        return False
    while d <= math.sqrt(x):
        if x%d == 0:
            return False
        d += 2
    return True
    
for i in range(times):
    num = int(input())
    if isPrime(num) == True:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
ls = []
counter = 0
for i in range(n):
	ls.append(int(input()))
for k in ls:
	s = 2
	ms = k
	if k == 2:
		counter += 1
	else:
		while ms >= s:
			if k % s == 0:
				break
			ms = k // s + 1
			s += 1
		else:
			counter += 1
print(counter)

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 1:
        return False
    for d in range(2, int(x ** 0.5)+1):
        if x % d == 0:
            return False
    return True


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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
count=0
def isprime(x):
    A=0
    for i in range(2,int(x**(0.5))+1):
        if x%i==0:
            A=1
            break
    if A==0:
        return True
    else:
        return False
for i in a:
    if isprime(i)==True:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import math

def isprime(n):
    if n==1:return False
    
    for k in range(2,int(math.floor(math.sqrt(n)))+1):
        if n%k==0:
            return False
            
    return True
    
n=int(input())
a=0

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

Submission status: Accepted

Solution code:
import math

def Sosu(N) :
    for i in range(2, int(math.sqrt(N))+1) :
        if N % i == 0 :
            return 'F'
    return 'T'
    

n = int(input())
ans = 0
for j in range(n) :
    a = int(input())
    if Sosu(a) == 'T' :
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
def isprime(N):
    if N==2:
        return True
    elif N<=1 or N%2==0:
        return False
    l = int(math.sqrt(N))
    for i in range(3,l+1,2):
        if N % i == 0:
            return False
        i += 2
    return True

N = int(input())
ans = 0
for i in range(N):
    ans += int(isprime(int(input())))
print(ans)

Submission status: Accepted

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

for _ in range(N):
  n = int(input())
  i = 2
  while i * i <= n:
    if n % i == 0:
      break
    i += 1
  else:
    a += 1

print(a)

Submission status: Accepted

Solution code:
import math

def isprime(N):
	if N == 2:
		return True
	if N <= 1 or N % 2 == 0:
		return False
	lim = int(math.sqrt(N))
	for i in range(3, lim + 1, 2):
		if N % i == 0:
			return False
		i += 2
	return True

N = int(input())
ans = 0
for i in range(N):
	ans += int(isprime(int(input())))
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
prime = n
for i in range(n):
    num = int(input())
    for j in range(2,int(math.sqrt(num)+1)):
      if num % j == 0:
       prime -= 1
       break
print(prime)

Submission status: Accepted

Solution code:
import math
n=int(input())
def sosu(a):
    for i in range(2,int(math.sqrt(a))+1):
        if a%i==0:
            return False
    return True
m=0
for i in range(n):
    a=int(input())
    if sosu(a):
        m+=1
print(m)

Submission status: Accepted

Solution code:
import math
def is_prime(x):
    if x == 1: return False
    for i in range(2,int(math.sqrt(x))+1):
        if x%i == 0: return False
    return True
n = int(input())
ans = 0
for i in range(n):
    x = int(input())
    ans += is_prime(x)
print(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
a=0
def prime(b) :
    for i in range(2,int(math.sqrt(b))+1):
        if b%i== 0:
            return False
    return True

for i in range(n) :
    if prime(int(input())) :
        a+=1

print(a)

Submission status: Accepted

Solution code:
import math
def is_prime(n):
    if n==1:
        return False
    for k in range(2,int(math.sqrt(n))+1):
        if n%k==0:
            return False
    return True
n=int(input())
m=0
c=0
while True:
    if m==n:
        break
    a=int(input())
    
    if is_prime(a)==True:
        c=c+1
 
    m=m+1
print(c)

Submission status: Accepted

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

n = int(input())
ans = 0
for _ in range(n):
    if is_prime(int(input())):
        ans += 1
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 0
	return 1

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math

ans = 0
while True:
   try:
      n = int(input())
      if n == 2:
         ans += 1
         continue
      if n % 2 == 0:
         continue
      
      c = 0
      for i in range(2, math.floor(math.sqrt(n)) + 1):
         if n % i == 0:
            c += 1
      if c == 0:
         #print("#", n)
         ans += 1

   except EOFError:
      break
   
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
p = 0

for i in range(n):
    x = int(input())
    if x == 2:
        p += 1
    elif x%2 == 1:
        j=3
        f = 0
        while j < (int(sqrt(x))+1):
            if x%j == 0:
                f = 1
                break
            else:
                j += 2
        if f == 0:
            p += 1
print(p)

Submission status: Accepted

Solution code:
def p(n):
  if n == 2: return 1
  if not n & 1: return 0
  return pow(2, n-1, n) == 1
print(sum(1 for _ in range(int(input())) if p(int(input()))))

Submission status: Accepted

Solution code:
import math
def prime(a):
    if a == 2 or a == 3:
        return True
    for i in range(2, int(math.sqrt(a))+2):
        if a%i == 0:
            return False
    return True

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

Submission status: Accepted

Solution code:
def is_prime(x):
    answer = True
    if x == 1:
        answer = False
    elif x == 2:
        answer = True
    elif x % 2 == 0:
        answer = False
    else:
        i = 3
        while i <= x ** 0.5:
            if x % i == 0:
                answer = False
                break
            i += 1
    return answer

if __name__ == "__main__":
    n = int(input())
    count = 0
    for _ in range(n):
        x = int(input())
        if is_prime(x):
            count += 1
        
    print(count)

Submission status: Accepted

Solution code:
import math
n = int(input())
a=[]
for i in range(n):
  a.append(int(input()))
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
b=0
for ai in a:
  if isprime(ai) == True:
    b += 1
print(b)

Submission status: Accepted

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

def is_prime(m: int)->bool:
    m2 = int(math.sqrt(m))+1
    for j in range(2, m2):
        if m % j == 0:
            return True
    else:
        return False

for i in range (n):
    m = int(input())
    if is_prime(m): a += 0
    else:
        a+=1
print (a)

Submission status: Accepted

Solution code:
import math



    
    
def isPrime(x):
        if x==2:
            return True
            
        if x<2 or x%2==0:
            return False
        a=int(math.sqrt(x))
        for i in range(3,a+1,2):
            if x%i==0:
                return False
            i+=2
        return True
    
x=int(input())
ans=0
for i in range(x):
    ans+=int(isPrime(int(input())))
    
print(ans)

Submission status: Accepted

Solution code:
def Prime(n):
    for i in range(2,n):
        if i * i > n:
            return True
        if n % i == 0:
            return False
    return True

n = int(input())
count = 0
for i in range(n):
    x = int(input())
    count += Prime(x)
print(count)

Submission status: Accepted

Solution code:
import math
def sosuu(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
    
c = 0
while True:
    try:
        x = int(input())
    except:
        break
    if sosuu(x) == True:
        c += 1
print(c)

Submission status: Accepted

Solution code:
import math

def isprime(N):
	if N == 2:
		return True
	if N <= 1 or N % 2 == 0:
		return False
	lim = int(math.sqrt(N))
	for i in range(3, lim + 1, 2):
		if N % i == 0:
			return False
		i += 2
	return True

N = int(input())
ans = 0
for i in range(N):
	ans += int(isprime(int(input())))
print(ans)

Submission status: Accepted

Solution code:
#合成数xはp<=x**0.5を満たす素因子pを持つ
def prime_number(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())
count = 0
for _ in range(N):
    i = int(input())
    count += prime_number(i)
print(count)

Submission status: Accepted

Solution code:
import math as ma

num = int(input())
ans = 0
for i in range(num):
    x = int(input())
    ok = 1
    for j in range(2,int(ma.sqrt(x)+1)):
        if (x % j == 0):
            ok = 0
            break
    ans += ok

print(ans)

Submission status: Accepted

Solution code:
import math
a = []
cnt = 0
n = int(input())
for _ in range(n) : 
	a.append(int(input()))

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
	
for i in a : 
	if isPrime(i) :
		cnt += 1
	
print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

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

counter = 0
for i in range(n):
    if isPrime(x[i]) == True:
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
import math

def using_sqrt(number):
    #numberが素数であればTrue,違うならFalse
    for divisor in range(2,math.floor(math.sqrt(number))+1):
        if number % divisor == 0:
            return False
    return True

N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
cnt = 0
for i in range(n):
    b = True
    x = int(input())
    xroot = int(sqrt(x))
    for i in range(xroot+1):
        if i >= 2 and x%i == 0:
            b = False
            break
    if b == True:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

c =  0
for i in range(n):
    if isPrime(numbers[i]):
        c += 1

print(c)

Submission status: Accepted

Solution code:
import math


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


def main():
    n = int(input())
    count = 0

    for i in range(n):
        a = int(input())
        if is_prime(a):
            count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
count = 0

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

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

Submission status: Accepted

Solution code:
def is_prime(x):
    for d in range(2, int(x**.5)+1):
        if x%d == 0:
            return False
    return True

n = int(input())
print(sum(is_prime(int(input())) for _ in range(n)))

Submission status: Accepted

Solution code:
N = 10**4
primes = range(2, N+1)
for d in range(2, int(N**.5)+1):
  primes = [x for x in primes if x % d or x == d]

count = 0
for _ in range(int(input())):
    x = int(input())
    if x <= N:
        count += (x in primes)
    else:
        for prime in primes:
            if x % prime == 0:
                break
        else:
            count += 1
print(count)