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 ≤ 10 8  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

Solution (Python):
import math

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

N = int(input())
nums = [int(input()) for i in range(N)]
print(sum([isPrime(n) for n in nums]))

Solution (Python):
import math

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

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

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

    return True


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

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


if __name__ == '__main__' :
    main()

Solution (Python):
import sys


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

    
    n = abs(int(n))

    
    if n < 2:
        return False

    
    if n == 2: 
        return True    

    
    if not n & 1: 
        return False

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

    return True


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

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

print(answer)

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


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

Solution (Python):
def main():
    N = int(input())
    print(IsPrime(N))

def IsPrime(N):
    count = 0
    for i in range(N):
        inputNum = int(input())
        if(inputNum == 2):
            count += 1
            continue
        elif(inputNum % 2 == 0):
            continue

        flag = 0
        for j in range(3, int(pow(inputNum, 1/2))+1):
            if(inputNum % j == 0):
                flag = 1
                break
            else:
                continue
        if(flag == 0):
            count += 1
    
    return count

if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

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

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

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

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


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

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

Solution (Python):

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

Solution (Python):

n = int(input())

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

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

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

Solution (Python):


import sys
import math

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

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

Solution (Python):


import sys
import math

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

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

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

print(count)

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

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

Solution (Python):
import sys

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

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

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

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

	elif num % 2 == 0:
		return False

	else:
		count = 3

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

			elif num % count == 0:
				return False

			else:
				break

		return True


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

		if isPrime(i):
			count += 1

	print(count)

Solution (Python):
import math
n = int(input())
v = []

for _ in range(n):
    v.append(int(input()))

n_prime = 0
for v_ in v:
    isprime = True

    if v_ <= 1:
        continue

    for i in range(1+int(math.sqrt(v_))):
        if i <= 1:
            continue
        if v_ % i == 0:
            isprime = False
            break

    n_prime = n_prime + isprime

print(n_prime)

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

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

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

    return True

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

print(cnt)

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

Solution (Python):
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)

Solution (Python):
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()))]))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

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

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

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

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

Solution (Python):
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)

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

Solution (Python):
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));

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
from math import gcd

magic = [2, 7, 61]

def mul(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):
    
    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)

Solution (Python):

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)

Solution (Python):

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)

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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))

Solution (Python):

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)

Solution (Python):
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

Solution (Python):



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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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))

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

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

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

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

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

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

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

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

Solution (Python):
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()))))

Solution (Python):
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()))))

Solution (Python):
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()))))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):


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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):

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)