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

n = int(input())
numlist = []
count = 0

for i in range(n):
    numlist.append(int(input()))

for elem in numlist:
    if isPrime(elem):
        count += 1

print(count)

Submission status: Accepted

Solution code:
def is_composite(n):
    r,d,a = 0,0,n-1
    while a%2 == 0:
        a = a >> 1
        r += 1
    d = a
    for a in [2,7,61]:
        x = pow(a,d,n)
        if x == 1 or x == n-1:
            continue
        for i in range(r-1):
            x = pow(x,2,n)
            if x == n-1:
               break
        else:
            return True
    return False

def is_prime(n):
    if n in [2,7,61]:
        return True
    elif 0 in (n%2,n%7,n%61):
        return False
    else:
        return not is_composite(n)

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

print(cnt)

Submission status: Accepted

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

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

    return True

if __name__ == '__main__':
    count = 0
    for num in input_list:
        #print(is_prime(num))
        if is_prime(num):
            count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def isprime(x):
    if x == 2:
        return True
    if x % 2 == 0:
        return False
    for m in range(3, x):
        if m ** 2 > x: break
        if x % m == 0:
            return False
    return True

def main():
    # x,y = list(map(int, input().split()))
    n = int(input())
    ans = 0
    for _ in range(n):
        ans += isprime(int(input()))
    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())

import math

cnt = 0

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

Submission status: Accepted

Solution code:
import math


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

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

Submission status: Accepted

Solution code:
import math
n = int(input())
count = 0
def isPrime(x):
    if x==2:
        return True
    if x>2 and x%2==0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x%i == 0:
            return False
        i += 1
    return True

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

Submission status: Accepted

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


N = int(input())
count = 0

for _ in range(N):
    p = int(input())
    
    if isPrime(p):
        count += 1

print(count)

Submission status: Accepted

Solution code:
import math
N = int(input())
ans = 0
for i in range(N):
    a = int(input())
    if a!=2:
        an = math.ceil(math.sqrt(a))
    else:
        an = 1
    flag = 0
    for j in range(an-1):
        if a%(j+2) == 0:
            flag = 1
            break
            
    if flag == 0:
        ans+=1
        #print(a)
print(ans)

Submission status: Accepted

Solution code:
def isPrime(p):
    if p == 1:
        return False
    elif p == 2:
        return True
    else:
        i = 2
        while p >= i*i:
            if p%i == 0:
                return False
            i += 1
        return True

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

Submission status: Accepted

Solution code:
def prime(k):
    j=2
    while j**2 <= k:
        if k%j == 0:
            break
        j += 1
    if j**2 <= k or k == 1:
        return False
    else:
        return True
n = int(input())
a=[]
for i in range(n):
    a.append(int(input()))
x=0
for k in a:
    if prime(k):
        x += 1
print(x)

Submission status: Accepted

Solution code:
import math

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

if __name__ == '__main__':
    n = int(input())
    nump = 0
    for i in range(n):
        num = int(input())
        if isPrime(num):
            nump += 1
    
    print(nump)

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0
for i in range(n):
    p = int(input())
    if p == 2:
        continue
    for j in range(2, int(p**(1/2))+1):
        if p % j == 0:
            cnt +=1
            break
print(n - cnt)

Submission status: Accepted

Solution code:
import math
def is_prime(n):
    if n in [2, 3, 5]:
        return True
    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)]
res = len([i for i in nums if is_prime(i)])
print(res)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N = int(input())

minus = 0

for _ in range(N):
    number = int(input())
    if number != 2 and number%2 == 0:
        minus += 1
        continue
    i = 3
    while i*i <= number:
        if number%i == 0:
            minus += 1
            break
        i += 2

print("%d"%(N-minus))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

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:
num = int(input())

def prime(x):
    if x ==2 or x == 3:
        return True
    
    elif x < 2 or x % 2 == 0:
        return False
    
    
    elif x >3:
        i = 3
        while i <= int(x**0.5)+1:
            if x % i ==0:
                return False
                break
            i = i+2
        return True

count = 0
for i in range(num):
    j = int(input())
    if prime(j) == True:
        count +=1



print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
import math

n=int(input())

cou=0

for i in range(n):
    a=int(input())
    jg=True
    z=int(math.sqrt(a))+1
    for k in range(2,z):
        if a%k==0:
            jg=False
            break
    if jg==True:
        cou+=1

print(cou)

Submission status: Accepted

Solution code:
import math
n=int(input())
A=[]
for i in range(0,n):
    v=int(input())
    A.append(v)
p=0
for i in range(0,n):
    x=math.sqrt(A[i])
    x=int(x)
    if A[i]==2 or A[i]==3:
        p=p
    else:
        for ii in range(2,x+1):
            if A[i]%ii==0:
                p=p+1
                break
p=n-p
print(p)

Submission status: Accepted

Solution code:
import math

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

count=0

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 j in range(n):
  if isPrime(a[j]):
    count+=1

print(count)

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<=x**0.5:
            if x%i == 0:
                return False
            i += 2
        else:
            return True

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

Submission status: Accepted

Solution code:
import math
def is_prime(a):
    j=2
    while(math.sqrt(a)>=j):
        if a%j==0:
           
            return 0
        j+=1
    return 1


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

for a in A:
    ans+=is_prime(a)
print(ans)

Submission status: Accepted

Solution code:
def main():
    def is_prime(n):
        """
        input: n > 0
        output: True if n is prime,otherwise False
        """
        import math
        if n == 1: return False
        for i in range(2, int(math.sqrt(n)) + 1):
            if n%i == 0:
                return False
        else:
            return True


    N = int(input())
    A = [int(input()) for _ in range(N)]
    
    ans = 0
    for val in A:
        if is_prime(val):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
count = 0
for i in range(n):
    p = int(input())
    if p == 2 or p == 3:
        count+=1
    else:
        for j in range(2,int(math.sqrt(p))+1):
            if p%j == 0 and p != j:
                break
            if j == int(math.sqrt(p)):
                count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math 


n = int(input())

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

for i in range(n):
    idx = 1

    for j in range(2, int(math.sqrt(l[i])) + 1):
        if l[i] % j == 0:
            idx = 0
            break

    if idx == 1:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

N = int(input())
A = [0] * N
count = 0

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

for i in range(N):
  flag = 0
  for j in range(2, int(math.sqrt(A[i])) + 1):
        if A[i] % j == 0:
          flag = flag + 1
          break
  if flag == 0:
    count = count + 1

print(count)

Submission status: Accepted

Solution code:
#17D8101028I tou koutetsu  2019/10/3
#ID:tanghaozhe 
#python
import math
#==============================================================================
# str = input()
# list=str.split(" ")
#==============================================================================

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

#print(list)
count=0
for i in list:
    i=int(i)
    p=i
    flag=True
    n=int(math.sqrt(i))
    if i>=2:
        for j in range(2,n+1):
            if(p%j==0):
                flag=False
                break
    else:
        flag=False
    if flag==True:
        count=count+1
        #print(p)
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
    
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i = i+2
    
    return True
N = int(input())
A = [int(input()) for i in range(N)]
cnt = 0
for i in range(N):
    if isPrime(A[i]):
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def isPrime(A):
    cnt=0
    for i in A:
        if i==2:
            cnt=cnt+1
        k=int(math.sqrt(i))
        for j in range(2,k+2):
           # print(j)
            if i%2==0:
                break
            if i%j==0:
                break
            if j>=k:
                cnt=cnt+1
                break
    return cnt
n=int(input())
A=list()
for i in range(n):
    A.append(int(input()))
print(isPrime(A))

Submission status: Accepted

Solution code:
import math

def isprime(x):
    M=math.sqrt(x)
    if x==2:
        return True

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

    i=3
    while i<=M:
        if x%i==0:
            return False

        i=i+2

    return True

c=0
n=int(input())
for i in range(n):

    x=int(input())

    if isprime(x):
        c=c+1

print(c)

Submission status: Accepted

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

def is_prime(a):
    if a < 2: return False
    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 is_prime(a): ans += 1

print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
count = 0
for i in range(n):
    x = int(input())
    judge = True
    for j in range(2, int(sqrt(x))+1):
        if x % j == 0:
            judge = False
            break
    if(judge): count+=1
print(count)

Submission status: Accepted

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

n = int(input())
c = 0
for i in range(n):
    c += prime(int(input()))

print(c)

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=i+2
    return True
    
    
n=int(input())
a=[]

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

print(cnt)

Submission status: Accepted

Solution code:
import math
def prime_number(num):
    if num==2:
        return True
    elif num%2==0:
        return False
    else:
        flag=0
        for i in range(3,math.floor(num**0.5)+1,2):
            if num%i==0:
                flag=1
        if flag==0:
            return True
        else:
            return False
N = int(input())
counter=0
for i in range(N):
    num = int(input())
    if prime_number(num):
        counter+=1
print(counter)

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 += 2
    return True
        
m = int(input())
p_nums = []
max_num = 0
count = 0
for _ in range(m):
    n = int(input())
    if n in p_nums:
        count += 1
        continue
    if is_prime(n):
        p_nums.append(n)
        count += 1
print(count)

Submission status: Accepted

Solution code:
from math import sqrt

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

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

print(res)

Submission status: Accepted

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

def func(a):
    if a < 2:
        return False
    elif a == 2:
        return True
    elif a % 2 == 0:
        return False
    b = int(math.floor(math.sqrt(a)))
    for j in range(3,b+1,2):
        if a % j == 0:
            return False
    return True

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

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline
n = int(input())
int_list = [int(input()) for i in range(n)]

count = 0
for i in int_list:
    x = i ** 0.5
    min_int = math.ceil(x)
    check_list = []
    for j in range(2, min_int+1):
        if i % j == 0 and i >= j:
            check_list.append('C')
            break
        else:
            check_list.append('S')

    if 'C' not in check_list:
        count += 1
    if i == 2:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n=int(input())
ans=0
for _ in range(n):
    a=int(input())
    for i in range(2,int(a**.5)+1):
        if a%i==0:
            break
    else:
      ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def prime(x):
    for _ in range(2, int(x**(1/2)+1)):
        if x % _ == 0:
            return False
    return True

n = int(input())
anw = 0
for _ in range(n):
    if prime(int(input())):
        anw += 1
print(anw)

Submission status: Accepted

Solution code:
import math

n = int(input())

ans=0
for i in range(n):
    x = int(input())
    if x%2==0 and x!=2:
        pass
    else:
        limit=int(math.sqrt(x))
        judge=True

        for j in range(3,limit+1,2):
            if x%j==0:
                judge=False
                break

        if judge:
            ans+=1
            #print(x,": prime number")
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

count = 0
for num in nums:
    count += isprime(num)
    
print(count)

Submission status: Accepted

Solution code:
#coding: utf-8
import math

n = int(input())
pnc = list()
for i in range(n):
    pnc.append(int(input()))
maxpnc = max(pnc)

maxsieve = max(int(math.sqrt(maxpnc)), 10)
maxtemp = maxsieve + 1
maxcheck = int(math.sqrt(maxsieve))
sieve = [1 for i in range(maxtemp)]
sieve[0] = 0
sieve[1] = 0
x = 2
while x <= maxcheck:
    for i in range(2 * x, maxtemp, x):
        sieve[i] = 0
    x += 1
    while sieve[x] == 0:
        x += 1
pn = list()
for i in range(2, maxtemp):
    if sieve[i] == 1:
        pn.append(i)

ans = 0
for i in pnc:
    if i <= maxsieve:
        if i in pn:
            ans += 1
    else:
        judge = True
        for j in pn:
            if i % j == 0:
                judge = False
                break
        if judge:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

def is_prime(n):
    m = int(sqrt(n))
    for q in range(2, m + 1):
        if n % q == 0:
            return False
    return True

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


main()

Submission status: Accepted

Solution code:
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

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

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

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

if __name__ == "__main__":
    N = int(input())
    c = 0
    for i in range(N):
        x = int(input())
        c += prime_number(x)
    print(c)

Submission status: Accepted

Solution code:
import math

n = int(input())
a = sorted([int(input()) for i in range(n)])
max_sqrt = int(math.sqrt(a[-1]))
screen = list(range(2, max_sqrt+1))
index = 0

while index < len(screen):
    screen = screen[:index+1] + list(filter(lambda x: x % screen[index] != 0, screen[index+1:]))
    index += 1

b = []
for i in range(len(a)):
    is_prime = True
    for j in range(len(screen)):
        if a[i] != screen[j] and a[i] % screen[j] == 0:
            is_prime = False
            break
    if is_prime:
        b.append(a[i])

print(len(b))

Submission status: Accepted

Solution code:
prime_number=[]
def prime():
    for i in range(2,int((10**8)**0.5+1)):
        flag=1
        for j in prime_number:
            if i%j==0:flag=0
        if flag:prime_number.append(i)

def checker(n):
    for i in prime_number:
        if n==i:
            return True
        if n%i==0:return False
    return True

prime()
count=0
for i in list(int(input()) for j in range(int(input()))):
    if checker(i):count +=1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

def isPrime(n):
  if n < 2:
    return False
  if n == 2:
    return True
  if n%2==0:
    return False
  m=math.floor(math.sqrt(n))+1
  for p in range(3,m,2):
      if n % p == 0:
        return False
  return True
m=int(input())
n=[]
for i in range(m):
  n.append(int(input()))
cnt=0
for i in range(m):
  if isPrime(n[i]):
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# ALDS1_1_C - Prime Numbers
def is_prime(n: int) -> bool:
    """
    Evaluate prime or not.
    
    Args: n (int): an integer to be evaluted.
    Returns: (bool): prime or not.
    """
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            return False
    return True


def main():
    A = set(map(int, open(0).read().split()))
    ans = sum(is_prime(i) for i in A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    
    print(sum([is_prime(a) for a in A]))

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:
        return pow(2, x - 1, x) == 1
      
if __name__ == '__main__':
  N = int(input())
  cnt = 0
  for n in range(N):
    v = int(input())
    if is_prime(v):
      cnt += 1 
  print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
prime_numbers =[]
for i in range(n):
	a = int(input())
	if a == 2:
		prime_numbers.append(a)
	if a < 2 or a%2 ==0:
		None
	else:
		i = 3
		b = 0
		while i <= a**0.5:
			if a % i ==0:
				b = 1
				break
			i = i+2
		if b == 0:
			prime_numbers.append(a)

print(len(prime_numbers))

Submission status: Accepted

Solution code:

l = list(range(2,10000))

for i in range(len(l)):
    if l[i] == 0:
        continue
    for j in range(i+1,len(l)):
        if l[j] == 0:
            continue
        if l[j] % l[i] == 0:
            l[j] = 0
p = []
for i in l:
    if i==0:
        continue
    p.append(i)

num = int(input())
count = 0
for i in range(num):
    x = int(input())
    isP = True
    for j in p:
        if x == j:
            break
        if x%j == 0:
            isP = False
            break
    if isP:
        count +=1

print(count)

Submission status: Accepted

Solution code:
def isprime(x):

	if x == 2:
		return 1

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

	i = 3
	while i <= x**0.5:
		if x%i == 0:
			return 0
		i += 2

	return 1


def test():

	n = int(input())
	prime_counter = 0

	for i in range(n):

		x = int(input())

		prime_counter += isprime(x)
	
	print(prime_counter)


if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

#@pysnooper.snoop()
n=int(stdin.readline().rstrip())
m=0
for i in range(n):
    a=int(stdin.readline().rstrip())
    for j in range(2,int(a**0.5)+1):
        if a%j==0:
            break
    else:
        #print(a)
        m+=1
print(m)

Submission status: Accepted

Solution code:
import math

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

ans = 0
N = int(raw_input())
for _ in range(N):
    if isprime(int(raw_input())):
        ans += 1
print ans

Submission status: Accepted

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

import sys
from math import sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def is_prime(num):
    """ 素数判定 """
    if num < 2: 
        return False
    if num in [2, 3, 5]: 
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False
    # 疑似素数(2でも3でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    num_sqrt = sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step
    return True

N = INT()
ans = 0
for i in range(N):
    a = INT()
    if is_prime(a):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

def PrimeJudge(a):
    if a == 2:
        return 1
    if a < 2 or a % 2 ==0:
        return 0
    i = 3
    while i <= int(math.sqrt(a)):
        if a % i == 0:
            return 0
        i += 2
    return 1

count = 0
for i in range(n):
    if PrimeJudge(A[i])==1:
        count += 1
print(count)

Submission status: Accepted

Solution code:
def Input():
    N = int(input())
    nums = [int(input()) for _ in range(N)]
    return nums, N

def FindPrimeNums(nums, N):
    not_prime = 0
    
    for i in range(len(nums)):
        if nums[i] % 2 == 0:
            if nums[i] != 2:
                not_prime += 1
        else:
            for j in range(3, len(nums), 2):
                if j**2 > nums[i]:
                    break
                if nums[i] % j ==0:
                    not_prime += 1
                    break
   
    return N - not_prime
nums, N = Input()
print(FindPrimeNums(nums, N))

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 <= x**(0.5):
        if x%i==0:
            return False
        i+=2
    return True
 
if __name__=='__main__':
    N=int(input())
    cnt=0
    for _ in range(N):
        if is_prime(int(input())): cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
import math
   
def prime(num):
  if num==1 or num==2 or num==3:
    return True
  for i in range(2,int(math.sqrt(num))+1):
    if num%i==0:
      return False
  else:
    return True
   
n=int(input())
ans=0
for i in range(n):
  tmp=int(input())
  if prime(tmp):
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
import datetime as kim
from _heapq import heappush, heappop
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N = int(input())
not_prime = 0
 
for loop in range(N):
    num = int(input())
 
    if num%2 == 0:
        if num != 2:
            not_prime += 1
    else:
        for i in range(3,num,2):
            if i*i > num:
                break
            if num%i == 0:
                not_prime += 1
                break
 
print("%d"%(N-not_prime))

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:
def is_prime(x):
    if x==2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=x**0.5:
        if x%i==0:
            return 0
        i+=2
    return 1

n=int(input())
a=[int(input()) for i in range(n)]
c=0
for i in range(n):
    c+=is_prime(a[i])
print(c)

Submission status: Accepted

Solution code:
import math

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

n = int(input())
a = [int(input()) for _ in range(n)]
print(sum([1 if is_prime(i) else 0 for i in a]))