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 readinput():
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    return n,a

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

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

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

def getPrimes(n):
    '''n以下の素数のリストを返す'''
    p=[]
    for i in range(2,n+1):
        if isPrime(i):
            p.append(i)
    return p

def main(n,a):
    m=max(a)
    p=getPrimes(m)
    cnt=0
    for _ in a:
        if _ in p:
            cnt+=1
    return cnt

if __name__=='__main__':
    #n,a=readinput()
    #ans=main(n,a)
    n=int(input())
    cnt=0
    for i in range(n):
        x = int(input())
        if isPrime(x):
            cnt+=1
    print(cnt)

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

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

ans = 0
for i in Numbers:
    for j in range(2,int(math.sqrt(i))+1):
        if i%j==0:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
count = 0
def prime(n):
    if n < 2:
        return 0
    elif n == 2:
        return 1
    elif n % 2 == 0:
        return 0

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

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

print(count)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

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

n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
for i in range(n):
    if is_prime(A[i]):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

def isPrime(n):
  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
  
count = 0
n = int(input())
for i in range(n):
    x = int(input())
    if isPrime(x):
        count +=1

print(count)

Submission status: Accepted

Solution code:
import math

def calc(n):
    global p
    q = 1
    lst = list(range(2, math.floor(math.sqrt(n))+1))

    for i in lst:
        if n%i ==0:
            q =0
            break

    if q==1:
        p = p+1

p =0
num = int(input())

for i in range(num):
    inputnum = int(input())
    if inputnum ==2:
        p =p+1
    else:
        calc(inputnum)

print(p)

Submission status: Accepted

Solution code:
primes = []
for i in range(2, 10 ** 4):
    for j in primes:
        if i % j == 0:
            break
    else:
        primes.append(i)

n = int(input())
cnt = 0
for i in range(n):
    p = int(input())
    if p in primes:
        cnt += 1
    elif p > 10 ** 4:
        for j in primes:
            if p % j == 0:
                break
        else:
            cnt += 1
    else:
        pass
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def is_prime_v2(x: int) -> bool:
    if x == 2:
        return True

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

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


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

    for _ in range(n):
        num: int = int(input())
        if is_prime_v2(num) == True:
            count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    A = [I() for _ in range(n)]

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

    print([is_prime(i) for i in A].count(True))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True
n = int(input())
ans = 0
for _ in range(n):
    ans += int(is_prime(int(input())))
print(ans)

Submission status: Accepted

Solution code:
import math

def isPrime(x):
    if x==2:
        return True
    
    if x<2 or x%2==0: #偶数もNG
        return False
    
    i=3
    while  i<=math.sqrt(x):
        if x%i==0:
            return False
        i+=2
    return True
    
n=int(input())#1度目の入力
count=0
for i in range(n):
    a=int(input())
    if isPrime(a):
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
input_nums = [int(input()) for _ in range(n)]

primes = []
for i in range(2, 10000):
    is_prime = True
    # 今まででた素数で割っていくと、自身が素数かどうかわかる
    for p in primes:
        if i % p == 0:
            is_prime = False
    if is_prime:
        primes.append(i)


def check(n):
    for p in primes:
        if n <= p:
            return True
        if n % p == 0:
            return False
    return True


count = 0
for num in input_nums:
    if check(num):
        count += 1
print(count)

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 ** (1 / 2):
        if x % i == 0:
            return False
        i += 2
    return True

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

print(cnt)

Submission status: Accepted

Solution code:
import math as m

def is_prime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime_number = 7
    difference = 4
    while prime_number <= m.sqrt(x):
        if x % prime_number == 0:
            return False
        prime_number += difference
        difference = 6 - difference
    return True
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
for i in a:
    ans += 1 if is_prime(i) else 0
print(ans)

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

import sys

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

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 合成数xはp <= math.sqrt(x) を満たす素因子pを持つことを利用
import math

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

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

Submission status: Accepted

Solution code:
n = int(input())
count = 0
for _ in range(n):
    num = int(input())
    judge = True
    for p in range(2, int(num**0.5)+1):
        if num % p == 0:
            judge = False
            break
    if judge:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
num = [int(input()) for _ in range(n)]
cnt=0
for i in num:
    if i==2:
        cnt+=1
    if i<2 or i%2==0:
        continue
    j=3
   
    while j*j<=i:
        if i%j==0:
            break
        j+=2
    else:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
count = 0
for i in range(N):
    n = int(input())
    if (n != 2) * (n % 2 == 0):
        continue
    j = 3
    while j*j <= n:
        if n % j == 0:
            break
        j += 2
    if j*j > n:
        count += 1
print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def isPrime(x):
    if x > 2 and x % 2 == 0:
        return False
    if x == 1:
        return True
    for a in range(3,round(x**(1/2))+1,2):
        if x % a == 0:
            return False
    return True

n = int(input())

prime = []
for a in range(n):
    prime.append(int(input()))

count = 0
for a in prime:
    if isPrime(a):
        count += 1

print(count)

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

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

Submission status: Accepted

Solution code:
import math

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

  r = 0
  for _ in range(n):
    m = int(input())

    flag = True
    for i in range(int(math.sqrt(m)) - 1):
      if m % (i+2) == 0:
        flag = False
        break
      
    if flag:
      r += 1

  print(r)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math

def is_prime(a):
  if a == 2:
    return 1

  if 2 > a or a % 2 == 0:
    return 0
  
  v = 3
  while v <= math.sqrt(a):
    if a % v == 0:
      return 0
    v += 2
  return 1
  
num = int(input())
count = 0
while num > 0:
  i = int(input())
  count += is_prime(i)
  num -= 1
print(count)

Submission status: Accepted

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

n = int(input())
i, c = 0, 0

while n > i:
    a = int(input())
    if pnj(a):
        c += 1
    i += 1

print(c)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
cnt = 0
for i in range(0, n):
	j = int(input())
	if (1 <= j <= 3):
		continue
	if j % 2 == 0:
		cnt = cnt + 1
		continue
	k = int(math.sqrt(j))
	l = 3
	while l <= k:
		if j % l == 0:
			cnt = cnt + 1
			break
		l = l +1

print(n - cnt)

Submission status: Accepted

Solution code:
import math
def prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if  n % i == 0:
            return False
    return True
num_prime = []
k = 0
while True:
    try:
        n = input()
    except:
        break
    if prime(int(n)):
        if not int(n) in num_prime:
            k += 1
            num_prime.append(int(n))
print(k)

Submission status: Accepted

Solution code:
import math as m

def prime(n):
    if n <= 1:
        return False
    for i in range(2,int(m.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True
    
a = int(input())
x = []
for j in range(a):
    b = int(input())
    if prime(b):
        x.append(b)
print(len(x))

Submission status: Accepted

Solution code:
import math
def isPrime(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):
    a = int(input())
    b = isPrime(a)
    if b:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
cnt = 0

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

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

Submission status: Accepted

Solution code:
from math import sqrt


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

    return this_is_prime


n = int(input())

nums = [int(input()) for _ in range(n)]
count = 0
for num in nums:
    if is_prime(num):
        count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
[a.append(int(input())) for x in range(n)]
cnt=0
for i in a:
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            cnt+=1
            break
print(n-cnt)

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 = i + 2

    return True

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

Submission status: Accepted

Solution code:
# ALDS_1_C: Prime Numbers
import sys
from math import sqrt
n = int(input())


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

    return True


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

Submission status: Accepted

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

num_list = []
num_list2 = []
for i in range(N):
    num_list.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 = i + 2
  return True
  
for i in num_list:
    if not isprime(i):
        continue
    else:
        num_list2.append(i)
  
print(len(num_list2))

Submission status: Accepted

Solution code:
import math
countp = 0
a = int(input())
for j in range(a):
     n = int(input())
     if n > 1  :
         for i in range(2,math.floor(math.sqrt(n))+1 ): 
              if n % i == 0: 
                   break  
         else :
             countp += 1
            
print(countp)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

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

for _ in range(n):
    if isPrime(int(input())):
        c += 1

print (c)

Submission status: Accepted

Solution code:
def primeNumber(a):
  if ( a == 2 or a == 3 or a == 5):
    return True
  elif a % 2 == 0:
    return False
  else:
    b = int(a ** 0.5 + 0.5)
    b = b + 1 if b % 2 == 0 else b

    for b in range(b,2,-2)	:
      if a % b == 0 :
        return False

    return True

cnt = 0
N = int(input())
for i in range(N):
  k = int(input())
  pn = primeNumber(k)
  if pn == True:
    cnt +=1
    
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]

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

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

Submission status: Accepted

Solution code:
def isprime(p):
    import math
    if p == 2:
        return True
    
    if p < 2 or p % 2 == 0:
        return False

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

    return True

if __name__ == "__main__":
    num = int(input())
    p_cnt=0
    for i in range(num):
        p = int(input())
        if isprime(p):
            p_cnt += 1
    
    print(p_cnt)

Submission status: Accepted

Solution code:
import math

def is_prime(n):
    if n == 2:
        return True
    
    if n < 2 or 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())
nums = [int(input()) for _ in range(n)]


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

    
print(result)

Submission status: Accepted

Solution code:
import math

def is_prime(N :int) -> bool:
    if N < 2:
        return False

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

    return True

if __name__ == "__main__":
    N = int(input())
    
    ans = 0
    for i in range(N):
        num = int(input())
        if is_prime(num):
            ans += 1

    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# N = int(sys.stdin.readline())
import sys,bisect,math
sys.setrecursionlimit(15000)

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

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

print(sum(1 for e in A if isPrime(e)))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]


# 素数判定
# coding:utf8
import random

def is_prime3(q, k=50):
    q = abs(q)
    # 計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range (0,k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        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

ans=0
for i in range(n):
    if is_prime3(a[i],50):
        ans+=1

print(ans)

Submission status: Accepted

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

# 素数判定 O(n ** 0.5)
def is_prime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return n != 1 # 1のときは例外

cnt = 0
for v in A:
	if is_prime(v): cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def eratos():
    primes = []
    for i in range(2, 10**4):
        flag = True
        for p in primes:
            if i%p == 0:
                flag = False
        if flag:
            primes.append(i)
    return primes

def check(n, primes):
    for p in primes:
        if n <= p:
            return True
        if n%p == 0:
            return False
    return True

N = int(input())
primes = eratos()
ans = 0
for _ in range(N):
    n = int(input())
    if check(n, primes):
        ans += 1
print(ans)

Submission status: Accepted

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

for i in range(n):
    m = int(input())
    for k in range(2, int(math.sqrt(m))+1):
        if m % k == 0 and m != k:
            cnt_prime -= 1
            break
        
print(str(cnt_prime))

Submission status: Accepted

Solution code:
# Problem - 素数

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

# input
N = int(input())

# initialization
ans = 0
for i in range(N):
    num = int(input())
    if is_prime(num):
        ans += 1

# output
print(ans)

Submission status: Accepted

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

n = int(input())
prime = [int(input()) for i in range(n)]
cnt = 0
for i in prime:
    if sosu(i):
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

def isPrime(x):
    if x == 2:
        return 1
    if x % 2 == 0:
        return 0
    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())
cnt = 0
for i in range(n):
    num = int(input())
    judge = True
    if num == 2:
        pass
    elif num < 2 or num%2 == 0:
        judge = False
        pass
    else:
        j = 3
        while j <= num**0.5:
            if num%j == 0:
                judge = False
                break
            j += 2
    if judge == True:
        cnt += 1
print(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    q = int(input())
    cnt = 0
    for _ in range(q):
        n = int(input())
        i = 2
        f = True
        while i*i <= n and f:
            if n % i == 0:
                f=False
            i += 1
        if f:
            cnt += 1
    print(cnt)

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

    return True

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

print(ans)

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())
prime_count = 0

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

print(prime_count)

Submission status: Accepted

Solution code:
import math
N=int(input())
from sys import stdin
num_list=[3,5,7]

count=0
for i in range(N):
    flag=1
    cmd = int(stdin.readline().strip())

    if cmd==2 or cmd==3 or cmd==5 or cmd==7:
        count+=1
        continue
    if (cmd) % 2 == 0:
        continue
    else:
        for i in range(3,int(math.sqrt(cmd)+1),2):
            if cmd % i == 0:flag=0
        if flag==1:
            count+=1

print(count)

Submission status: Accepted

Solution code:
from math import floor

count = 0
n = int(input())

for _ in range(n):
    x = int(input())
    if x == 2 or x == 3:
        count += 1
    for i in range(2, floor(x**(1/2)) + 1):
        if x % i == 0:
            break
        if i == floor(x**(1/2)) and x % i != 0:
            count += 1
            
print(count)

Submission status: Accepted

Solution code:
from math import sqrt

def is_prime(a):
    if a<2:return 0
    if a==2:return 1
    if a%2 == 0:return 0
    i = 3
    while i<=sqrt(a):
        if a%i==0:return 0
        i+=2
    return 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0

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

for i in range(n):
    if isPrime(a[i]):
        ans += 1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N = int(input())


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

print(ans)

Submission status: Accepted

Solution code:
def isprime(p):
    if p <= 1:
        return False
    if p == 2:
        return True
    if p % 2 == 0:
        return False
    lim = int(p**0.5)+1
    for q in range(3, lim, 2):
        if p % q == 0:
            return False
    return True

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

ans = sum(isprime(a) for a in A)
print(ans)

Submission status: Accepted

Solution code:
import math
def prime(v):
  if v == 2: return 1
  if v > 2 and v % 2 == 0: return 0

  for i in range(int(math.sqrt(v)), 2, -1):
    if v % i == 0: return 0
  return 1

N = int(raw_input())
n = []
count = 0
for i in range(N):
  count += prime(int(raw_input()))
print count

Submission status: Accepted

Solution code:
import math

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

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

print(cnt)

Submission status: Accepted

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


if __name__ == "__main__":
    n = int(input())
    ans = 0
    for _ in range(n):
        num = int(input())
        ans += is_prime(num)
    print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
count = 0
for i in range(n):
    a = int(input())
    if (a == 2):
        count += 1
    else:
        for j in range(2, math.ceil(math.sqrt(a)) + 1):
            if (a % j == 0):
                break
        else:
            count += 1

print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

for i in range(n):
    k = int(input())
    if k != 2 and k % 2 == 0:
        continue
    
    if prime(k):
        count += 1

print(count)

Submission status: Accepted

Solution code:
def is_prime(num):
  if 2 < num and num % 2 == 0:
    return False

  n = num ** (1 / 2)

  cnt = 2

  while cnt <= n:
    if num % cnt == 0:
      return False
    cnt += 1
  
  return True

prime_num_cnt = 0

for i in range(int(input())):
  if is_prime(int(input())):
    prime_num_cnt += 1

print(prime_num_cnt)

Submission status: Accepted

Solution code:
#nの素数判定
def isPrime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

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