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:
import sys
readline = sys.stdin.readline
prime = set([2])
for i in range(3, 10000, 2):
    for j in prime:
        if i % j == 0:
            break
    else:
        prime.add(i)
n = int(input())
cnt = 0
for i in (int(readline()) for _ in range(n)):
    if i in prime:
        cnt += 1
        continue
    for j in prime:
        if i % j == 0:
            break
    else:
        cnt += 1
print(cnt)

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
print(sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))]))

Submission status: Accepted

Solution code:
import sys

count = 0

number = int(input())

for line in sys.stdin:
    n = int(line)
    if n == 2:
        count += 1
        continue

    if n % 2 == 0:
        continue

    jdg = True
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            jdg = False
            break
    if jdg:
        count += 1

print(count)

Submission status: Accepted

Solution code:
c=0
n=int(input())
for _ in range(n):
 x=int(input())
 for i in range(2,int(x**.5+1)):
  if x%i==0:c+=1;break
print(n-c)

Submission status: Accepted

Solution code:
c=0
n=int(input())
for _ in range(n):
 x=int(input())
 if x!=2 and x%2==0:c+=1;continue
 for i in range(3,int(x**.5+1),2):
  if x%i==0:c+=1;break
print(n-c)

Submission status: Accepted

Solution code:
n=int(input())
c=0
for _ in range(n):
 x=int(input())
 if 2 in [x,pow(2,x,x)]:c+=1
print(c)

Submission status: Accepted

Solution code:
n=int(input())
c=0
for _ in range(n):
 x=int(input())
 if x==2:c+=1
 elif pow(2,x-1,x)==1:c+=1
print(c)

Submission status: Accepted

Solution code:
n=int(input())
c=0
for _ in range(n):
 x=int(input())
 if 1 in [x-1,pow(2,x-1,x)]:c+=1
print(c)

Submission status: Accepted

Solution code:
n=int(input())
c=0
for _ in[0]*n:
 x=int(input())
 if 2 in[x,pow(2,x,x)]:c+=1
print(c)

Submission status: Accepted

Solution code:
c=0
for _ in[0]*int(input()):
 x=int(input())
 if 2 in[x,pow(2,x,x)]:c+=1
print(c)

Submission status: Accepted

Solution code:
import sys
input();c=0
for e in sys.stdin:
 x=int(e)
 if 2 in[x,pow(2,x,x)]:c+=1
print(c)

Submission status: Accepted

Solution code:
import sys
input();c=0
for x in map(int,sys.stdin):
 if 2 in[x,pow(2,x,x)]:c+=1
print(c)

Submission status: Accepted

Solution code:
from math import sqrt;

count = int(input());
data = [];
for n in range(count):
    data.append(int(input()));

def prime_number(data):
    max_divisor = get_max_divisor(data);
    divisor_primes = get_prime(max_divisor);
    count = 0;
    for n in data:
        ok = 1;
        for p in divisor_primes:
            if n < p:
                ok = 0;
                break;
            elif n == p:
                break;
            elif n % p == 0:
                ok = 0;
                break;
        count += ok;
    return count;

def get_max_divisor(data):
    maxN = data[0];
    for n in data[1:]:
        if n > maxN:
            maxN = n;
    return int(sqrt(maxN)) + 1;

def get_prime(max_divisor):
    primes = [];
    for n in range(2, max_divisor + 1):
        is_prime = True;
        for p in primes:
            if n % p == 0:
                is_prime = False;
        if is_prime:
            primes.append(n);
    return primes;

print(prime_number(data));

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


if __name__ == '__main__':

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

    count = 0
    for n in nums:
        if isprime(n):
            count += 1

    print(count)

Submission status: Accepted

Solution code:
def prime(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, cnt = int(input()), 0
for i in range(n):
    x = int(input())
    if prime(x):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import gcd

magic = [2, 7, 61]

def mul(a, b, n):
    # calculate (a * b) % n
    r, a, b = 0, a % n, b % n
    while b:
        if b & 1:
            r = (a + r) % n
        a = (a + a) % n
        b >>= 1
    return r

def bigmod(a, p, n):
    # calculate (a ** p) % n
    if p == 0:
        return 1
    if p == 1:
        return a % n
    return mul(bigmod(mul(a, a, n), p // 2, n), a if p % 2 else 1, n)

def miller_rabin(n, a):
    if gcd(a, n) == n:
        return True
    if gcd(a, n) != 1:
        return False
    d, r = n-1, 0
    while d % 2 == 0:
        d /= 2
        r += 1
    res = bigmod(a, d, n)
    if res == 1 or res == n-1:
        return True
    while r:
        r -= 1
        res = mul(res, res, n)
        if res == n-1:
            return True
    return False

def isPrime(n):
    for a in magic:
        if not miller_rabin(n, a):
            return False
    return True


num = int(input())
ans = sum(map(int, [isPrime(int(input())) for _ in range(num)]))
print(ans)

Submission status: Accepted

Solution code:
# coding: UTF-8
n = int(raw_input())
count = 0
for i in range(n):
    num = int(raw_input())
    if (num < 2):
        continue
    elif (num == 2):
        count += 1
        continue
    elif (num % 2 == 0):
        continue
    if pow(2,num-1,num) == 1:
        count += 1
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import sqrt
from bisect import bisect

def inpl(): return tuple(map(int, input().split()))

def isprime(N, P):
    if N <= 1:
        return False
    for p in P[:bisect(P, sqrt(N))]:
        if N%p==0:
            return False
            break
    else:
        return True

def primes(N):
    P = [2]
    searched = [False]*(N+1)
    for i in range(3, N+1, 2):
        if searched[i]:
            continue
        P.append(i)
        for j in range(i, N+1, i):
            searched[j] = True
    return P

P = primes(int(sqrt(10**8)))

res = 0
for i in range(int(input())):
    res += isprime(int(input()), P)
print(res)

Submission status: Accepted

Solution code:
import math

def isprime(z):
    if z == 2:
        return True
    
    if z < 2 or z % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(z):
        if z % i == 0:
            return False
        i += 2
    return True

if __name__ == '__main__':
    n = int(input())
    c = 0
    for _ in range(n):
        if isprime(int(input())):
            c += 1
    print (c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import sqrt
from bisect import bisect

def inpl(): return tuple(map(int, input().split()))

def isprime(N, P):
    if N <= 1:
        return False
    for p in P[:bisect(P, sqrt(N))]:
        if N%p==0:
            return False
            break
    else:
        return True

def primes(N):
    P = [2]
    searched = [False]*(N+1)
    for i in range(3, N+1, 2):
        if searched[i]:
            continue
        P.append(i)
        searched[i:N+1:i] = [True]*(N//i)
    return P

P = primes(int(sqrt(10**8)))

res = 0
for i in range(int(input())):
    res += isprime(int(input()), P)
print(res)

Submission status: Accepted

Solution code:
def isprime(n):
    from math import floor,sqrt
    if n <= 1:
        return False
    for i in range(2,floor(sqrt(n))+1):
        if n % i == 0:
            return False
    return True

n = int(input())
ans = []
for i in range(n):
    po = int(input())
    if isprime(po):
        ans.append(po)  
print(len(ans))

Submission status: Accepted

Solution code:
#coding: UTF-8
def isPrime(n):
  if n == 1:
    return False
  import math
  m = math.floor(math.sqrt(n))
  for i in range(2,m+1):
    if n % i == 0:
      return False
  return True

n = int(input())
count = 0
for j in range(n):
  m = int(input())
  if isPrime(m):
    count += 1

print(count)

Submission status: Accepted

Solution code:
import math
import sys

def is_prime(x):
    if x == 1: return 0
    elif x == 2: return 1
    elif x % 2 == 0: return 0

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

n = int(raw_input())
count = 0
for i in range(n):
    x = int(raw_input())
    count += is_prime(x)

print count

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

MAX_PRIME = 10**4
def prime_list():
    sqrt_max = int(MAX_PRIME ** 0.5)
    primes = [True for i in range(MAX_PRIME+1)]
    primes[0] = primes[1] = False

    for p in range(sqrt_max):
        if primes[p]:
            for px in range(p*2, MAX_PRIME, p):
                primes[px] = False

    p_list = [i for i in range(MAX_PRIME) if primes[i]]
    return p_list


def is_prime(n, prime_list):
    sqrt_n = int(n ** 0.5)
    for i in prime_list:
        if i > sqrt_n:
            break
        if n % i == 0:
            return False
    return True

p_list = prime_list()

n = int(sys.stdin.readline())
num_p = 0

for i in range(n):
    x = int(sys.stdin.readline())
    if is_prime(x, p_list):
        num_p += 1
print(num_p)

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:
from math import sqrt

def prime_numbers(n):
    total = 0
    for x in n:
        if is_prime(x):
            total += 1
    return total

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

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

if __name__ == '__main__':
    n = []
    for _ in range(int(input())):
        n.append(int(input()))
    print(prime_numbers(n))

Submission status: Accepted

Solution code:
from math import sqrt

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

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

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

    return True


row_num = int(input())
count = 0
for row in range(row_num):
    if isPrime(int(input())):
        count += 1

print(count)

Submission status: Accepted

Solution code:
def isprime(n):
    if n < 2: return 0
    elif n == 2: return 1

    if n % 2 == 0: return 0

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

    return 1

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

a = [i for i in n if isprime(i)]

print(len(a))

Submission status: Accepted

Solution code:
import sys
input()
print(sum(2 in[x,pow(2,x,x)]for x in map(int,sys.stdin)))

Submission status: Accepted

Solution code:
import sys
input()
print(sum(1 for x in map(int,sys.stdin)if 2 in[x,pow(2,x,x)]))

Submission status: Accepted

Solution code:
import sys
input()
print(len([1 for x in map(int,sys.stdin)if 2 in[x,pow(2,x,x)]]))

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:
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(x):
    if x == 1:
        return False
    p = int(pow(x, 0.5)) + 1
    i = 2
    while i <= p and i < x:
        if x % i == 0:
            return False
        else:
            i += 1
    return True

n = int(input())
c = 0
i = 0
while i < n:
    x = int(input())
    if IsPrime(x) == True:
        c += 1
    i += 1
print(c)

Submission status: Accepted

Solution code:
import math
cnt = 0
for i in range(int(input())):
    x = int(input())
    flg = False # なんらかの数で割り切れるかどうか
    if x == 1:
        continue
    if x == 2:
        cnt += 1
        continue
    for k in range(2, math.floor(math.sqrt(x))+1):
        if not(x % k):
            flg = True
            break
    if not flg:
        cnt += 1
print(cnt)

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:
from math import sqrt
n = int(input())
p = 0

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



print(p)

Submission status: Accepted

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

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



print(p)

Submission status: Accepted

Solution code:
import math


def is_prime(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 = int(input())
numbers = [int(input()) for i in range(n)]


count = 0
for i in range(n):
    if is_prime(numbers[i]) is True:
        count += 1

print(count)

Submission status: Accepted

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

c = 0
for _ in range(int(input())):
  c += is_prime(int(input()))
print(c)

Submission status: Accepted

Solution code:
import math


def is_prime(n):
    """return True if n is a prime number

    >>> is_prime(1)
    False
    >>> is_prime(7)
    True
    >>> is_prime(81)
    False
    """
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

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

    return True


def run():
    count = int(input())
    nums = []
    for i in range(count):
        nums.append(int(input()))

    print('{}'.format(len(list(filter(is_prime, nums)))))


if __name__ == '__main__':
    run()

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
    for i in range(3, int(math.sqrt(x)) + 1):
        if x % i == 0:
            return False
    return True


if __name__ == '__main__':

    n = int(input())
    cnt = 0
    for _ in range(n):
        x = int(input())
        if isPrime(x):
            cnt += 1

    print(cnt)

Submission status: Accepted

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

def ifprime(num):
  for i in range(2,math.floor(num ** 0.5) + 1):
    if num % i:
      continue
    else:
      return False
  return True

for _ in range(n):
  a = int(input())
  if ifprime(a):
    count += 1

print(count)

Submission status: Accepted

Solution code:
import math
def isprime(x):
    if x ==2:
        return True
    if x<2 or x%2 ==0:
        return False
    else:
        sx = int(math.sqrt(x))
        for i in range(3,sx+1,2):
            if x%i ==0:
                return False
            
        return True
a = 0
n = int(input())
for i in range(n):
    a+= isprime(int(input()))
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

for i in range(n):
    a_sq = int(math.sqrt(A[i]))
    for j in range(2,a_sq+2):
        if(A[i]%j==0 and not(A[i]==j)):
            break
        if(j==a_sq+1):
            cou += 1

print(cou)

Submission status: Accepted

Solution code:
import math
def prime(x):
    if x == 2:
        return 1
    elif x < 2 or x % 2 == 0:
        return 0
    i = 3
    while(i <= math.sqrt(x)):
        if x % i == 0:
            return 0
        i += 2
    return 1

n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
s = 0
for i in range(n):
    if prime(x[i]) == 1:
        s += 1
print(s)

Submission status: Accepted

Solution code:
import math
def isprime(x):
    if x==2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=math.sqrt(x):
        if x%i==0:
            return 0
        i=i+2
    return 1

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

for i in range(n):
    if isprime(A[i]):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

cnt = 0
n = int(input())

for i in range(n):
    flg = 1
    x = int(input())
    if x == 2: cnt += 1
    elif x % 2 != 0:
        rx = int(math.sqrt(x))
        for i in range(3, rx+1):
            if x % i == 0:
                flg = 0
                break
        if flg == 1: cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

def Eratos(n):
	primes = [2]
	num = [2*i+1 for i in range(1,n//2)]
	tmp = []

	top = 1
	while top < math.sqrt(n):
		top = num[0]
		for i in range(1,len(num)):
			if num[i] % top != 0:
				tmp.append(num[i])
		num = tmp
		tmp = []
		primes.append(top)
	for i in range(len(num)):
		primes.append(num[i])
	return primes

n = int(input())
cont = 0
primes = Eratos(20000)
for i in range(n):
	a = int(input())
	if a<10000:
		if primes.count(a)!=0:
			cont += 1
	else:
		for j in range(len(primes)):
			if a%primes[j]==0:
				break
			else:
				if math.sqrt(a)<primes[j]:
					cont += 1
					break
print(cont)

Submission status: Accepted

Solution code:
import math

def Eratos(n):
	primes = [2]
	num = [2*i+1 for i in range(1,n//2)]
	tmp = []

	top = 1
	while top < math.sqrt(n):
		top = num[0]
		for i in range(1,len(num)):
			if num[i] % top != 0:
				tmp.append(num[i])
		num = tmp
		tmp = []
		primes.append(top)
	for i in range(len(num)):
		primes.append(num[i])
	return primes

n = int(input())
cont = 0
primes = Eratos(15000)
for i in range(n):
	a = int(input())
	if a<10000:
		if primes.count(a)!=0:
			cont += 1
	else:
		for j in range(len(primes)):
			if a%primes[j]==0:
				break
			else:
				if math.sqrt(a)<primes[j]:
					cont += 1
					break
print(cont)

Submission status: Accepted

Solution code:
import math

def Eratos(n):
	primes = [2]
	num = [2*i+1 for i in range(1,n//2)]
	tmp = []

	top = 1
	while top < math.sqrt(n):
		top = num[0]
		for i in range(1,len(num)):
			if num[i] % top != 0:
				tmp.append(num[i])
		num = tmp
		tmp = []
		primes.append(top)
	for i in range(len(num)):
		primes.append(num[i])
	return primes

n = int(input())
cont = 0
primes = Eratos(10010)
for i in range(n):
	a = int(input())
	if a<10000:
		if primes.count(a)!=0:
			cont += 1
	else:
		for j in range(len(primes)):
			if a%primes[j]==0:
				break
			else:
				if math.sqrt(a)<primes[j]:
					cont += 1
					break
print(cont)

Submission status: Accepted

Solution code:
from math import sqrt

n=int(input())

count=0

for i in range(n):
    x=int(input())
    if x==1:
        count=count+1
    elif x!=2 and x%2==0:
        count=count+1
    elif x==2 or x==3 or x==5:
        count=count
    else:
        for j in range(2,int(sqrt(x))+1): 
            if x%j==0:
                count=count+1
                break


print(n-count)

Submission status: Accepted

Solution code:

def is_prime(n):

    if n == 2:
        return True
    elif n < 2 or n & 1 == 0:
        return False
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

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

Submission status: Accepted

Solution code:
#16D8101012J 伊藤惇 dj Python3
import math

def Prime_Numbers(x):
    i=2
    flag=True
    while i <= math.sqrt(x):
        if x%i==0:
            flag=False  
            break
        i+=1
    return flag
if __name__ == "__main__":
    A=[]
    n=int(input())
    for i in range(n):
        A.append(int(input()))
    sum=0
    for i in A:
        if Prime_Numbers(i):
            sum+=1
    print(sum)

Submission status: Accepted

Solution code:
#16D8101012J 伊藤惇 dj Python3
import math

def Prime_Numbers_Check(x):
    i=2
    flag=True
    while i <= math.sqrt(x):
        if x%i==0:
            flag=False  
            break
        i+=1
    return flag
def Prime_Numbers_Count(A):
    sum=0
    for i in A:
        if Prime_Numbers_Check(i):
            sum+=1
    return sum

if __name__ == "__main__":
    A=[]
    n=int(input())
    for i in range(n):
        A.append(int(input()))
    sum=Prime_Numbers_Count(A)
    print(sum)

Submission status: Accepted

Solution code:
import math
n=int(input())
A=[0]*n
cnt=0
for i in range(0,n):
    A[i]=int(input())
for i in range(0,n):
    if A[i]<2: pass
    elif A[i]==2 or A[i]==3 or A[i]==5 or A[i]==7:
        cnt+=1
    else:
        x=int(math.sqrt(A[i])+1)
        for j in range(2,x):
            if A[i]%j==0:
                break
            else: pass
            if j==x-1:
                cnt+=1
            else: pass
print(cnt)

Submission status: Accepted

Solution code:
import math

n=int(input())
A=[0 for i in range(n)]
cnt=0
for i in range(n):
    A[i]=int(input())
for i in range(n):
    a=int(math.sqrt(A[i])+1)
    if A[i]<2: pass
    elif A[i]==2 or A[i]==3 or A[i]==5 or A[i]==7:
        cnt+=1
    else:
        for j in range(2,a):
            if A[i]%j==0:
                break
            if j==a-1:
                cnt+=1
print(cnt)

Submission status: Accepted

Solution code:

import math

n=int(input())

sum=0

for i in range(n):
	b=1
	n=int(input())
	for j in range(2,int(math.sqrt(n))+1):
		if n%j==0:
			b=0
			break
	sum+=b
			
print(sum)

Submission status: Accepted

Solution code:
import math
def PrimeNum(a):
	x=math.sqrt(a)
	x=int(x)
	tmp=1
	if a==1:
		tmp=0
	elif a==2:
		tmp==1
	elif a>3 and a<9:
		for i in range(2,a):
			st=a%i
			if st==0:
				tmp=0
				break
	
	else:
		for i in range(2,x+1):
			st=a%i
			if st == 0:
				tmp=0
				break
	#print("::::",a,x,st,tmp)
		
	#if tmp==1:print("・・")

	return tmp	
	
n=int(input())
p=[]
att=0
for i in range(n):
	p.append(int(input()))
	att+=PrimeNum(p[i])
	
print(att)

Submission status: Accepted

Solution code:
import math
def s(x):
    r=0
    s=math.sqrt(x)
    s=(int)(s)
    for i in range(2,s+1):
        w=x%i
        if w==0:
            r=r+1
    return r
N=int(input())
A=[0 for i in range(N)]
for i in range(N):
    A[i]=int(input())
t=0
i=2
for i in range(N):
    r=s(A[i])
    if r==0:
        t=t+1
print(t)

Submission status: Accepted

Solution code:
import math

N=int(input())

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

c=0 
cnt=0

for k in range(N):
	x=math.sqrt(A[k])
	x=(int)(x)
	for j in range(2,x+1):
		if A[k]%j==0:
			cnt+=1
			break
	if cnt==0:
		c+=1
	
	cnt=0


print(c)

Submission status: Accepted

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

for i in range(n):
  a.append(input())
cnt=0
b=[int(i) for i in a]

for i in range(n):
    c=math.sqrt(b[i])
    c=int(c)
    if b[i]==2:
      cnt+=1
    for j in range(2,b[i]):
      if b[i]%j==0:
        break
      if math.sqrt(b[i])<j:
        cnt+=1
        break
print(cnt)

Submission status: Accepted

Solution code:
#ALDS 1-C: Prime Numbers
import math

n = int(input())
c = 0
for i in range(n):
    x = int(input())
    f = 1
    for j in range(2,int(math.sqrt(x))+1):
        if x % j == 0: 
            f = 0
            break
    c = c + f
print(c)

Submission status: Accepted

Solution code:
import math
def jud(s):
    for i in range(2,int(math.sqrt(s))+1):
            if s%i == 0:
                return 0
    return 1

n = int(input())
a = [0]*n
cnt = 0

for i in range(n):
    a[i] = int(input())
    han = jud(a[i])
    if han == 1:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

def s(x):
    r=0
    s=math.sqrt(x)
    s=(int)(s)

    for i in range(2,s+1):
        w=x%i
        if w==0:
            r=r+1
    return r

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

t=0
i=2
for i in range(N):
    r=s(A[i])
    if r==0:
        t=t+1
print(t)

Submission status: Accepted

Solution code:
#16D8101023J 久保田凌弥 kubotarouxxx python3
import math as mh
a=int(input())
A=[0]*a
x=0
for i in range(a):
 A[i]=int(input())
 for j in range(1,A[i]):
  if A[i]==2:
    x+=1
    continue
  if j==1:
   continue
  elif (A[i]%j)==0:
   break
  elif j>=mh.sqrt(A[i]):
   x+=1
   break
print(x)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
#! python3
# prime_number.py

import math

def is_prime_number(x):
    if x < 2: return False
    elif x == 2: return True
    elif x%2 == 0: return False

    sqrt_upper_bound = math.floor(math.sqrt(x))+1
    for i in range(3, sqrt_upper_bound, 2):
        if x % i == 0:
            return False

    return True

n = int(input())
prime_num = 0
for i in range(n):
    x = int(input())
    if is_prime_number(x):
        prime_num += 1

print(prime_num)

Submission status: Accepted

Solution code:
import math
n=int(input())
R=[0]*n
sum=0
for i in range(n):
    R[i]=int(input())
for i in range(n):
    if R[i]<0:
        continue
    s=math.sqrt(R[i])
    s=int(s)+1
    for j in range(2,s+1):
        if R[i]==j:
            sum=sum+1
        if R[i]%j==0:
            break
        if j==s:
            sum=sum+1
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
a =[]
for i in range(n):
    a.append(int(input()))
#n = 10000
p = []   
pc = [True for _ in range(10001)]
pc[0] = False
pc[1] = False

for i in range(2,10001):
    if pc[i]:
        #print(i, pc[i])
        p.append(i)
        for j in range(i,10001,i):
            pc[j] = False

cnt = 0
for i in a:
    if i<=10000:
        if i in p:
            cnt += 1
    else:
        isp = True
        for j in p:
            if i%j == 0:
                isp = False
                break
        if isp:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
input()
def f():print(sum(2 in[x,pow(2,x,x)]for x in map(int,sys.stdin)))
f()

Submission status: Accepted

Solution code:
import sys
input()
print(sum(2 in[x,pow(2,x,x)]for x in map(int,sys.stdin.readlines())))

Submission status: Accepted

Solution code:
import sys
input()
def s():print(sum(2 in[x,pow(2,x,x)]for x in map(int,sys.stdin.readlines())))
if'__main__'==__name__:s()

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
for a in li:
    flag = True
    for i in range(2, int(a**0.5)+1):
        if a % i == 0:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
def is_prime(x):
    if x == 1 or x == 2:
        return True

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

    return True

def main():
    n = int(input())
    cnt = 0
    for _ in range(n):
        if is_prime(int(input())):
            cnt += 1

    print(cnt)

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math


def Isprime(num):
    for j in range(2, int(math.sqrt(num)) + 1):
        if num % j == 0:
            return 0
    return 1


count = 0
n = int(input())
for i in range(n):
    num = int(input())
    count += Isprime(num)

print(count)

Submission status: Accepted

Solution code:
import math

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


if __name__ == '__main__':
    n = int(input())
    prime_numbers = []

    for i in range(n):
        num = int(input())
        if is_prime(num):
            prime_numbers.append(num)

    print(len(prime_numbers))

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(input()) for i in range(n)]
prime_num = 0

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


for i in nums:
    if(prime(i)):
        prime_num += 1

print(prime_num)

Submission status: Accepted

Solution code:
import sys
import math

#num = [int(i) for i in sys.argv[2:]]
n = input()
num = [int(i) for i in sys.stdin.readlines()]
count = 0

for i in num:
    if i == 1:
        continue
    elif i == 2:
        #print(i)
        count += 1
        continue

    square = int(math.sqrt(i))

    for j in range(2, square+1):
        if i % j == 0:
            break
    else:
        #print(i)
        count += 1

print(count)

Submission status: Accepted

Solution code:
import math

def prime_numbers(numbers):
    return list(map(is_prime, numbers)).count(True)


def is_prime(n):
    if (n == 2):
        return True
    elif (n % 2 == 0):
        return False
    else:
        i = 3
        while i <= math.sqrt(n):
            if n % i == 0:
                return False
            i += 2

    return True

if __name__ == '__main__':
    n = int(input())
    numbers = []
    for i in range(0, n):
        numbers.append(int(input()))
    print(prime_numbers(numbers))

Submission status: Accepted

Solution code:
n=int(input())
c=0
for i in range(n):
    p=int(input())
    if pow(2,p-1,p)==1 or p==2:
        c+=1
print(c)