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:
# -*- coding : utf-8 -*-

import math

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

list_num = int(input())
count_prime = 0
for i in range(list_num):
    num = int(input())
    if is_prime_number(num):
        count_prime = count_prime + 1
print(count_prime)

Submission status: Accepted

Solution code:
import math


def is_prime(num):
    if num == 2:
        return True
    elif not num & 1:
        return False

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


N = int(input())
nums = [int(input()) for _ in range(N)]
ans = len([num for num in nums if is_prime(num)])
print(ans)

Submission status: Accepted

Solution code:
def is_prime(n):
    if n == 1:
        return False
    elif n == 2 or n == 3:
        return True
    elif n % 2 == 0:
        return False
    else:
        for i in range(3, int(n ** 0.5) + 1, 2):
            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:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif n%2==0: return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,1000),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,100),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,50),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,30),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,20),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7,11): return True
    elif 0 in (n%2,n%3,n%5,n%7,n%11): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d = n-1
        s = 0
        while not d%2:d,s = d>>1,s+1
        return maybe_prime(d,s,n)

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

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:d,s = d>>1,s+1
        return maybe_prime(d,s,n)

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

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x in (1,n-1):continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:d,s = d>>1,s+1
        return maybe_prime(d,s,n)

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

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)

        if x in (1,n-1): continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True
 
def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1
 
print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                break
        else:
            return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,50),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                break
        else:
                return False
    return True
 
def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1
 
print(cnt)

Submission status: Accepted

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

import math


def is_prime(x):
    # Primality Test
    if x == 2:
        return True

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

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


def to_int(v):
    return int(v)


if __name__ == '__main__':
    l = to_int(input())
    seq = [to_int(input()) for i in range(l)]
    cnt = 0

    for v in seq:
        if is_prime(v):
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
#import time
#start = time.time()

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


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

count = 0
for a in data:
    if isPrimeNumber(a):
        count += 1
print(count)
#end = time.time()
#print(end - start)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import math
count = 0
while True:
    try:
        n = int(input())
        if n == 2 or n == 3 or n == 5 or n == 7:
            count += 1
        if n > 3 and n % 2 != 0:
            for i in range(3,int(math.sqrt(n))+1):
                if n % i == 0:
                    break
                elif i == int(math.sqrt(n)):
                    count += 1
    except  EOFError:
        break
print(count)

Submission status: Accepted

Solution code:
import math

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


def count_prime_numbers(number_list):
    cnt = 0
    for target in number_list:
        if isprime(target):
            cnt += 1
    return cnt

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

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    p = int(input())
    if not p%2:
        if p != 2:
            n -= 1
        continue
    for j in range(3,int(p**0.5)+1,2):
        if not p%j:
            n -= 1
            break
print(n)

Submission status: Accepted

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

def devisor(n):
    if n == 2:
        return 1
    else:
        if n < 2 or n % 2 == 0:
            return 0
        elif pow(2,n-1,n) == 1:
            return 1
        else: return 0

for i in range(n):
    x = int(input())
    c += devisor(x)

print(c)

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:
from math import sqrt
def isPrime(n):
    if n == 2:
        return 1
    if n == 1 or n % 2 == 0:
        return 0
    for i in range(3,int(sqrt(n)) + 1):
        if n % i == 0:
            return 0
    return 1

from sys import stdin
print(sum([isPrime(int(n))for n in stdin]))

Submission status: Accepted

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

for i in range(n):
    data = int(input())
    data = abs(data)
    if data == 2:
        count += 1
    elif pow(2,data-1,data) == 1:
            count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N = int(input())

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

ctr = 0

for j in range(N):
	if Z[j] == 2:
		ctr += 1
	elif Z[j] < 2 or (Z[j] % 2) == 0:
		pass
	else:
		Up = math.sqrt(Z[j])
		k = 3
		while k<= Up:
			if (Z[j] % k) == 0:
				break
			else:
				k += 1
		else:
			ctr += 1

print(ctr)

Submission status: Accepted

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

def isprime(x):
    if x == 2:
        return True
    elif x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i += 2
    else:
        return True
   
counter = 0
for i in a:
    if isprime(i) == True:
        counter += 1
print(counter)

Submission status: Accepted

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

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


input_num = int(raw_input())
counter = 0
found_number = 0
while counter < input_num:
    candidate_number = int(raw_input())
    if prime_number_identifier(candidate_number):
        found_number += 1
    counter += 1

print found_number

Submission status: Accepted

Solution code:
def isPrimeNum(in_num):
    if in_num <= 1:
        return False
    elif in_num == 2:
        return True
    elif in_num % 2 == 0:
        return False
    else:
        if pow(2, in_num-1, in_num) == 1:
            return True
        else:
            return False


num_len = int(input())
cnt = 0
for i in range(num_len):
    num = int(input())
    if isPrimeNum(num)==True:
        cnt = cnt + 1

print(str(cnt))

Submission status: Accepted

Solution code:
import math
n = input()
A = 0

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

for i in range(n):
	k = input()
	if is_prime(k):
		A += 1

print A

Submission status: Accepted

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

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:
from math import sqrt
def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i, xx = 3, int(sqrt(x))
    while i <= xx:
        if x % i == 0:
            return False
        i = i + 2
    return True

N = int(input())
print(sum([1 for _ in range(N) if isPrime(int(input()))]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import math
i = input()
count=0

def isPrime(x):
    global count
    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+=2
    return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt
res = 0

def isprime(x) :
    if x == 2 : return 1
    if (x < 2) or (x % 2 == 0) : return 0

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

    return 1

for mak in range(int(input())) :
    res += isprime(int(input()))
print(res)

Submission status: Accepted

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

import sys
import os
import math


N = int(input())


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

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

print(cnt)

Submission status: Accepted

Solution code:
import math

p = [2]
    
def isprime(x):
    if x == 2:
        return True
    if x == 3:
        return True
    if max(p) < x**0.5:
        for j in range(max(p), math.floor(x**0.5) + 1):
            if all([j % k != 0 for k in p]):
                p.append(j)
    i = 0
    while i <= len(p)-1:
        if x%p[i] == 0:
            return False
        if p[i] > x**0.5:
            break;
        i += 1
    return True


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

Submission status: Accepted

Solution code:
import sys
import math

def isprime(n):
    if n == 2:
        return 1
    if n < 2 or n % 2 == 0:
        return 0

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

n = int(input())
p = 0
for i in map(int, sys.stdin.readlines()):
    p += isprime(i)

print(p)

Submission status: Accepted

Solution code:
def prime_number(a):
    if a ==2 : return True

    if not a==1 and not a%2==0:
        k = 3
        while k <= a**(1/2):
            if a % k == 0:
                return False
                break
            k += 2
        return True


count_pn = 0
for i in range(int(input())):
    a = int(input())
    if prime_number(a):
        count_pn += 1
print(count_pn)

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

Solution code:
import sys

def solve():
    n = int(sys.stdin.readline())
    ans = 0

    for i in range(n):
        num = int(sys.stdin.readline())

        ans += is_prime(num)

    print(ans)

def is_prime(n):
    if n < 2:
        return False

    for p in range(2, n + 1):
        if p*p > n:
            break
        if n % p == 0:
            return False

    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    n = int(sys.stdin.readline())
    ans = 0

    for i in range(n):
        num = int(sys.stdin.readline())

        ans += is_prime(num)

    print(ans)

def is_prime(n):
    if n < 2 or (n > 2 and n & 1 == 0):
        return False

    for p in range(3, n + 1, 2):
        if p*p > n:
            break
        if n % p == 0:
            return False

    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    n = int(sys.stdin.readline())
    ans = 0

    for i in range(n):
        num = int(sys.stdin.readline())

        ans += is_prime(num)

    print(ans)

def is_prime(n):
    if n < 2 or (n > 2 and n & 1 == 0):
        return False

    p = 3

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

        p += 2

    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    n = int(sys.stdin.readline())

    ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n))

    print(ans)

def is_prime(n):
    if n < 2:
        return False

    p = 2

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

        p += 1

    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    n = int(sys.stdin.readline())

    ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n))

    print(ans)

def is_prime(n):
    if n < 2 or (n > 2 and n & 1 == 0):
        return False

    p = 3

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

        p += 2

    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    n = int(sys.stdin.readline())

    ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n))

    print(ans)

def is_prime(n):
    if n < 2 or (n > 2 and not(n & 1)):
        return False

    for p in range(3, n, 2):
        if p*p > n:
            break
        if not(n % p):
            return False

    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
from math import sqrt

def solve():
    n = int(sys.stdin.readline())

    ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n))

    print(ans)

def is_prime(n):
    if n < 2 or (n > 2 and not(n & 1)):
        return False

    lim = int(sqrt(n)) + 1

    for p in range(3, lim, 2):
        if not(n % p):
            return False
            
    return True

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math

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

    if (x == 1) or (x % 2 == 0):
        return False

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

    return True
    
if __name__ == '__main__':
    element_number = int(input())
    input_array = [int(input()) for i in range(element_number)]

    output = 0
    for x in input_array:
        if(is_prime(x)):
            output += 1

    print(output)

Submission status: Accepted

Solution code:
import math

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

    if (x == 1) or (x%2 == 0):
        return False

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

    return True
    
if __name__ == '__main__':
    element_number = int(input())
    input_array = [int(input()) for i in range(element_number)]

    output = 0
    for x in input_array:
        if(is_prime(x)):
            output += 1

    print(output)

Submission status: Accepted

Solution code:
import sys
import math

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

    if (x == 1) or (x % 2 == 0):
        return False

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

    return True
    
if __name__ == '__main__':
    element_number = int(input())

    output = 0
    for x in map(int, sys.stdin.readlines()):
        if(is_prime(x)):
            output += 1

    print(output)

Submission status: Accepted

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

num = []
prime_numbers = []

n = int(input())

for _ in range(n):
    i = int(input())
    num.append(i)

for i in num:
    if is_prime(i):
        prime_numbers.append(i)

print(len(prime_numbers))

Submission status: Accepted

Solution code:
#ALDS1_1-C Prime Numbers
def prime(n):
    s=3
    while(s*s <= n):
        if(n%s==0):
            return False
        s+=2
    return True

n=int(input())
num=0
for i in range(n):
    x = int(input())
    if prime(x) and x%2!=0:
        num+=1
    if x==2:
        num+=1
print(num)

Submission status: Accepted

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


def prime_number():
    n = int(input())
    count = 0
    for _ in range(n):
        a = int(input())
        if isPrime(a):
            count += 1
    print(count)

if __name__ == "__main__":
    prime_number()

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())
cnt = 0
for i in range(n):
 x = int(input())
 if isprime(x):
  cnt += 1
print(str(cnt))

Submission status: Accepted

Solution code:
import math

n = int(input())
prime = n

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

print(prime)

Submission status: Accepted

Solution code:
import sys
prime = lambda x: True if x==2 else False if x<2 or not x%2 else pow(2,x-1,x)==1
inp = sys.stdin.readlines()
print(len([prime(e) for e in list(map(int, inp[1:])) if prime(e)==1]))

Submission status: Accepted

Solution code:
import math
cnt = 0
N = int(input())
for i in range(N):
    n = int(input())
    if n % 2:
        area = round(math.sqrt(n))
        prime_ng = 0
        for i in range(2, area + 1):
            if n % i == 0:
                prime_ng = 1
                break
        if prime_ng == 0:
            cnt += 1
    elif n == 2:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    nums = [int(n) for n in stdin]

    primes = list(filter(is_prime, nums))
    print(len(primes))

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

    if 2 == n:
        return True

    if 0 == n % 2:
        return False

    for i in range(3, n, 2):
        if not i <= int(n/i):
            break

        if 0 == n % i:
            return False

    return True

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(n):
    k = int(input())
    j = 2
    flag = 0
    while k/j >= j:
        if k % j == 0:
            flag = 1
            break
        j += 1
    if flag == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

if __name__=="__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    b = []
    for i in range(n):
        b.append(is_prime3(a[i]))
    print(b.count(True))

Submission status: Accepted

Solution code:
import math
cnt = 0
N = int(input())
for n in range(N):
    i = int(input())
    if i == 2\
    or i == 3\
    or i == 5\
    or i == 7:
        cnt += 1
    elif i % 2 == 0:
        continue
    else:
        j = 3
        prime = 1
        while j >= 3 and j <= int(math.sqrt(i)):
            if i % j == 0:
                prime = 0
                break
                
            j += 2
        if prime == 1:
            cnt += 1

print(cnt)