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 chk(n):
	if n < 2 == 0:
		return False
	if n == 2:
		return True
	if n % 2 == 0:
		return False

	x = int(math.sqrt(n))
	sw = True
	i = 3
	while i <= x:
		if n % i == 0:
			sw = False
			break
		i += 1
	return sw

cnt = 0
while 1:
	try:
		n = int(input())
		sw = chk(n)
		if sw == True:
			cnt += 1
	except:
		break
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt

li = []
N = int(input())
for _ in range(N):
    li.append(int(input()))

# li = [5, 2, 3, 4, 5, 6]
li = set(li)

count = 0
for v in li:
    if v == 2:
        count += 1
    elif v % 2 == 0:
        continue
    else:
        ubd = int(sqrt(v))
        flag = 1
        for i in range(3, ubd+1):
            if v % i == 0:
                flag = 0
                break
        count += flag

print(count)

Submission status: Accepted

Solution code:
def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    x = 3
    while x * x <= n:
        if n % x == 0:
            return False
        x += 2
    return True


N = int(input())
ans = 0
for _ in range(N):
    n = int(input())
    ans += is_prime(n)
print(ans)

Submission status: Accepted

Solution code:
import math
N=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
    
ans=0

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

Submission status: Accepted

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

# def prime_table(m: int) -> list:
#     prime = [False] * (m + 1)
#     prime[0] = False
#     prime[1] = False
#     for i in range(2, (m + 1)):
#         if prime[i]:
#             continue
#         for j in range(i, (m + 1)):
#             if i * j > m:
#                 break
#             prime[i * j] = True
#     return prime

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

if __name__ == "__main__":
    res = 0
    for i in range(n):
        if is_prime(int(input())):
            res += 1
    print(res)

Submission status: Accepted

Solution code:
def is_prime(x: int) -> bool:
    """自然数nが素数であるかを判定する
    計算量: O(sqrt(N))
    """
    if x == 2:
        return True
    if x == 1 or x % 2 == 0:
        return False
    for k in range(3, int(x ** 0.5) + 1, 2):
        if x % k == 0:
            return False
    return True


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

ans = 0
for num in a:
    if is_prime(num):
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def isPrime(n):
    if n == 2 or n == 3:
        return True
    if n % 2 == 0 or n < 2:
        return False
    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 i in range(N):
    a = int(input())
    if isPrime(a):
        count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
count = 0
for i in range(n):
    x = int(input())
    tf = True
    
    if x == 2:
        tf = True
    elif x < 2 or x % 2 == 0:
        tf = False
    else:
        j = 3
        while j <= (x)**(1/2):
            if x % j == 0:
                tf = False
                break
            j += 2
            tf == True
    
    if tf == True:
        count += 1
print(count)

Submission status: Accepted

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

cnt = 0

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
 
for i in range(n):
        if isprime(a[i]):
            cnt += 1
            
print(cnt)

Submission status: Accepted

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

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

res_list = [i for i in num_list if prime_chk(i)]
print(len(res_list))

Submission status: Accepted

Solution code:
import math

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

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

print(prime_count)

Submission status: Accepted

Solution code:
import math

def get_input():
    return int(input())

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

  if x < 2 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

n = get_input()
results = 0
for _ in range(n):
    a = get_input()
    if isprime(a):
        results += 1

print(results)

Submission status: Accepted

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

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

print(len([i for i in a if isPrime(i)]))

Submission status: Accepted

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

for i in range(n):
    m = int(input())
    if m == 2 or m == 3:
        c +=1
    else:
        T = 1
        for k in range(2,math.ceil(math.sqrt(m))+1):
            if m % k == 0:
                T = 0
                break
        if T == 1:
            c +=1
print(c)

Submission status: Accepted

Solution code:
_, *A = map(int, open(0).read().split())

ret = 0
for a in A:
    if a == 2:
        ret += 1
    else:
        if a % 2 == 0:
            continue
        else:
            flag = True
            for i in range(3, int(a**0.5)+2, 2):
                if a % i == 0:
                    flag = False
                    break
            if flag:
                ret += 1
                
print(ret)

Submission status: Accepted

Solution code:
import math

n = int(input())

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

answer = 0
for i in range(n):
    count = 0
    dest = int(math.sqrt(nums[i])) + 1

    prime = True
    for j in range(2, dest):
        if nums[i] % j == 0:
            prime = False
            break

    if (nums[i] != 1) and prime:
        answer += 1

print(answer)

Submission status: Accepted

Solution code:
n=int(input())
count=0
for i in range(n):
    a=int(input())
    flag=0
    if a==2:
        count+=1
        continue
    elif a<2 or a%2==0:
        continue
    for i in range(2,int(a**0.5)+1):
        if a%i==0:
            flag=1
            break
    if flag==0:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import math

count = 0

def calculate(y):
    i = 3
    if y==2:
        return y
    elif y<2 or y%2==0:
        return False
    while i<= math.sqrt(y):
        if y % i == 0:
            return False
        i += 2
    return y

x = int(input())
y = [int(input()) for _ in range(x)] #入力は縦だが、リストに格納される優れもの。

for l in y:
    if calculate(l)!=False:
        count += 1
print(count)

Submission status: Accepted

Solution code:
# 合成数 x は p ≤ √x を満たす素因子 p をもつ
# x が素数かどうかは，2~√xまでの範囲を調べればよい

def is_Prime(x): #xが素数かどうかを調べる
   if x == 2: # 2なら素数
      return x
   if x < 2 or x % 2 == 0: # 2未満or偶数ならFalse
      return False
   for i in range(3, x, 2): # 3からxまでステップ2で
      if i * i > x: # √xまで調べる
         break
      if x % i == 0: # 合成数ならFalse
         return False
   return x

N = int(input())
num_list = [int(input()) for _ in range(N)] # 1つの数字をN行入力
count = 0
for i in num_list: # 各数字について調べる
   prime = is_Prime(i)
   if prime != False: # 素数だった数字のみカウントする
      count+=1
print(count)

Submission status: Accepted

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

ans = 0

for i in ints:
    if i == 2:
        ans += 1
        continue

    if i < 2 or i % 2 == 0:
        continue
    
    j = 3
    flag = True
    while j <= math.sqrt(i):
        if i % j == 0:
            flag = False
            break
        j += 1
    if flag: ans += 1

print(ans)

Submission status: Accepted

Solution code:
import time
import random
import sys
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math

inf = 10**9


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

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

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

    return True


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

    for i in range(n):
        x = int(input())
        if isPrime(x):
            count = count + 1
            # print(x, "is prime number")

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def is_prime(num):
    m = int(math.sqrt(num))

    for i in range(2, m + 1):

        if num == 2:
            return True

        elif num % i == 0:
            return False
    
    return True

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

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

    print(count)

main()

Submission status: Accepted

Solution code:
#素数を求めるプログラム
def isprime(x):
    if x <= 2:
        return True
    elif x % 2 == 0:
        return False
    else:
        i = 3
        while i <= int(x**0.5)+1:
            if x % i == 0:
                return False
            i += 2
        return True

#入力dataの挿入
input_number = int(input())
result_data = list()
for i in range(input_number):
    result_data.append(isprime(int(input())))

#処理の実行
print(sum(result_data))

Submission status: Accepted

Solution code:
# Algorithms and Data Structures 1
# Prime Numbers
# Name: Ryuya Asada
# ID s1260064


import math


def isPrimes(n: int) -> bool:
    if n == 2:
        return True

    if 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 main():
    number_of_numbers = int(input())
    number_of_primes = 0

    for i in range(0, number_of_numbers):
        n = int(input())
        if isPrimes(n):
            number_of_primes += 1

    print(number_of_primes)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

def prime_number(num):
    if num == 1:
        return False

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

    return True

count = 0
n = int(input().rstrip())
for i in range(n):
    num = int(input().rstrip())
    judge = prime_number(num)
    if judge == True:
        count += 1

print(count)

Submission status: Accepted

Solution code:
import math

def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, math.ceil(math.sqrt(n))+1, 2):
        if n % i == 0:
            return False
    return True
    
n = int(input())
ans = 0
for _ in range(n):
    x = int(input())
    if is_prime(x):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
i = int(input())
answer = 0
for _ in range(i):
    n = int(input())
    if n <= 1:
        continue
    elif n == 2:
        answer += 1
    else:
        if 0 == n % 2:
            continue
        else:
            x = 3
            answer += 1
            while x <= math.sqrt(n):
                if 0 == n % x:
                    answer -= 1
                    break
                x = x + 2
print(answer)

Submission status: Accepted

Solution code:
#Prime Numbers

import math

def is_prime(n):
    if n <= 3:
        return True
    
    if n % 2 == 0:
        return False 

    limit = int(math.sqrt(n)) + 1
    limit = limit if limit < n//2 else n//2 + 1

    for i in range(3,limit,2):
        if n % i == 0:
            return False
        #print(f"i:{i}")  # dbg
    
    return True

n = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math


def is_prime(x: int):
    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


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

print(ans)

Submission status: Accepted

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


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

    return True


N = int(input())
result = 0
for _ in range(N):
    x = int(input())
    if is_prime(x):
        # print('{} is prime'.format(x))
        result += 1

print(result)

Submission status: Accepted

Solution code:
N = int(input())


def isPrime(n):
    if n == 2: return True
    elif n <= 1:return False
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            return False
        i += 1
    return True


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

Submission status: Accepted

Solution code:

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

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

    return True

n = int(input())

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

Submission status: Accepted

Solution code:
"""
素数を求める
素数以外の数 = 合成数
「合成数 x は p ≤ _√xを満たす素因子 p をもつ」
"""


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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())
count = 0

for i in range(N):
    a = int(input())
    if is_prime(a):
        count += 1

print(count)

Submission status: Accepted

Solution code:
def is_prime(n):
    for i in range(2, n-1):
        if n % i == 0:
            return False
        if i * i > n:
            break
    return True


ans = 0
while True:
    try:
        n = int(input())
        if is_prime(n):
            ans += 1
    except EOFError:
        break

print(ans)

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 1:
        return False
    i = 2
    n = x
    while i < n:
        if x % i == 0:
            return False
        n = x // i
        i += 1
    return True


n = int(input())
ret = []
for i in range(n):
    x = int(input())
    if is_prime(x):
        ret.append(x)
print(len(ret))

Submission status: Accepted

Solution code:
def main():

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

	print(count)

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


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
#1_C
def isprime(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 = i + 2

    return True

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())


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


cnt = 0

for _ in range(n):
    if improved_is_prime(int(input())):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
N=int(input())
a=[]
c=0
"""
def isPrime( x ):
    if x <= 1:
        return False

    for i in range(2,x-1):
        if x % i == 0:
            return False

    return True
"""

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 range(N):
    n=int(input())
    a.append(n)
    
for i in range(N):
    if(isPrime(a[i])==True):
        c=c+1

print(c)

Submission status: Accepted

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


n = int(input())
nums = [int(input()) for _ in range(n)]
ans = sum([1 for i in nums if is_prime(i)])
print(ans)

Submission status: Accepted

Solution code:
import math

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


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

Submission status: Accepted

Solution code:
import math

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


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

Submission status: Accepted

Solution code:
import math

def get_primes(num):
    
    lim = math.sqrt(num)
    prime = []
    data = [i+1 for i in range(1, num)]
    
    while True:
        
        if data[0] >= lim:
            return prime + data
        
        prime.append(data[0])
        data = [i for i in data if i % data[0] != 0]

def is_prime(num, prime_arr):
    for i in prime_arr:
        if num <= i:
            return True
        if num % i == 0:
            return False
    return True

prime_arr = get_primes(10000)

N = int(input())

prime_count = 0
for i in range(N):
    num = int(input())
    if is_prime(num, prime_arr):
        prime_count += 1

print(prime_count)

Submission status: Accepted

Solution code:
from collections import Counter

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

N = int(input())
nums = [int(input()) for i in range(N)]
Nums = Counter(nums)
c = 0
for a in Nums.keys():
    if prime(a):
        c += Nums[a]
print(c)

Submission status: Accepted

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

if __name__=='__main__':
    N = int(input())
    count = 0
    for _ in range(N):
        if isPrime(int(input())):
            count += 1
    print(count)

Submission status: Accepted

Solution code:
import math
def isPrime(x):
	if(x<2):
		return False
	else:
		for i in range(2,int(math.sqrt(x)//1)+1):
			if(x%i==0):
				return False
		return True

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

Submission status: Accepted

Solution code:


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


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

print(cnt)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
cnt=n
for i in range(n):
	a=int(input())
	if a==1:
		cnt-=1
		continue
	for j in range(2,min(int(a**0.5)+2,a)):
		if a%j==0:
			cnt-=1
			break
print(cnt)

Submission status: Accepted

Solution code:
A, *N,  = [int(s.split()[0]) for s in open(0)]
cnt = 0
for n in N:
    p = round(n**0.5)
    for i in range(2, p + 1):
        if n % i == 0:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

def is_prime(n):
    if n == 1: return False
    
    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):
    x = int(input())
    if is_prime(x):
        ans += 1
        
print(ans)

Submission status: Accepted

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    array = sc.intarr_ver(n)
    count = 0
    for i in array:
        count += natural_num(i)
    print(count)


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


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


main()

Submission status: Accepted

Solution code:
import math

n = input()
b = int(n) - 1

num = []
maxnum = 0

nnc = int(0)

for j in range(int(n)):
	inpn = int(input())
	if inpn < 2 or inpn % 2 == 0:
		if inpn != 2:
			continue
		else:
			nnc += 1
			continue
	num.append(inpn)
	if maxnum < inpn:
		maxnum = inpn



rx = math.sqrt(maxnum)
rx += 2

#nature number counter

for i in range(3, int(rx),2):
	for j in reversed(num):
		if math.sqrt(j) < i:
			nnc += 1
			num.remove(j)
		elif j%i == 0:
			num.remove(j)

nnc += len(num)

print(nnc)

Submission status: Accepted

Solution code:
def cnt_primenumber(arr):
    cnt = 0
    for i in range(len(arr)):
        if arr[i] == 1:
            continue
        flag = 1
        for j in range(2,int(arr[i]**0.5)+1):
            if arr[i] % j == 0:
                flag = 0
                break
        if flag:
            cnt += 1
    return cnt

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

print(cnt_primenumber(ls))

Submission status: Accepted

Solution code:
def p(n):
    import math
    a = math.floor(n**(1/2))
    if n == 2:
        return n
    elif n == 1:
        return 1
    elif n%2 == 0:
        return 1
    else:
        for i in range(3,a+1):
            if n%i == 0:
               return 1
    return n
N = int(input())           
c = 0
for i in range(N):
    n = int(input())
    if p(n) != 1:
        c += 1
print(c)

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_1_C
# ここに来てめちゃくちゃ簡単になったぞどうした？


from math import sqrt


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


# load data
N = int(input())
ans = 0
for _ in range(N):
    x = int(input())
    ans += is_prime(x)

print(ans)

Submission status: Accepted

Solution code:
def main():
    A = set()
    n_prime = 0
    while True:
        try:
            x = int(input())
            A.add(x)
        except:
            break

    for x in A:
        n_prime += is_prime(x)

    print(n_prime)


def is_prime(x):  
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:
        return pow(2, x - 1, x) == 1   

main()

Submission status: Accepted

Solution code:
import math


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

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


def main():
    num_el = int(input())
    nums = [int(input()) for i in range(num_el)]
    are_primes = [is_prime(num) for num in nums]
    print(sum(are_primes))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
prime_count = 0
for _ in range(n):
    num = int(input())
    num_sqrt = math.floor(math.sqrt(num))
    is_prime = True
    for d in range(2, num_sqrt+1):
        if num % d == 0:
            is_prime = False
            break
    if is_prime:
        prime_count += 1
print(prime_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for _ in range(n):
    p = int(input())
    for q in range(2,int(p**0.5)+1):
        if p%q == 0: break
    else: ans += 1
print(ans)

Submission status: Accepted

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

print(N - minus)

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):
        if n % i == 0:
            return False
    
    return True

num = int(input())
num_list = []
for i in range(num):
    num_list.append(int(input()))

prime_count = 0
for n in num_list:
    if is_prime(n):
        prime_count += 1

print(prime_count)

Submission status: Accepted

Solution code:
import math

def is_prime(n):
    if n == 2:
        return 1
    elif n % 2 == 0:
        return 0
    for x in range(3, math.ceil(math.sqrt(n)) + 1, 2):
        if n % x == 0:
            return 0
    return 1


N = int(input())
print(sum(is_prime(int(input())) for _ in range(N)))

Submission status: Accepted

Solution code:
def check_prime(n):
    root_n = n ** 0.5
    for i in range(2, int(root_n) + 1):
        if n == i:
            continue
        elif n % i == 0:
            return 0
    return 1

ans = 0
for i in range(int(input())):
    num = int(input())
    ans += check_prime(num)
print(ans)

Submission status: Accepted

Solution code:
import math

def is_prime(x):
    j = 2
    while j <= math.floor(x ** (1/2)) + 1 and x != 2:
        if x % j == 0:
            return False
        j += 1
    return True

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

Submission status: Accepted

Solution code:
def isPrime(n):
    p = 2
    while p * p <= val:
        if val % p == 0 :
            return False
    
        p +=1
    return True    
t = int(input())
cnt = 0
for i in range(t):
    val = int(input())
    if isPrime(val):
        cnt +=1

print(cnt)

Submission status: Accepted

Solution code:
import math
def isPrimeNum(num):
    sqrtNum = int(math.sqrt(num)) + 1
    if(num == 2 or num == 3):
        return True
    elif(num % 2 == 0):
        return False
    else:
        for i in range(3, sqrtNum , 2):
            if(num % i == 0 ):
                return False
        return True
    
count = 0
N = int(input())
for i in range(N):
    num = int(input())
    if(isPrimeNum(num)):
        count += 1

print(count)

Submission status: Accepted

Solution code:
isp = [True for _ in range(10005)]
isp[0] = isp[1] = False
for p in range(10005):
    if not isp[p]:
        continue
    for i in range(2, 10000):
        if p * i > 10000:
            break
        isp[p*i] = False
primes = list(filter(lambda x: isp[x], range(10000)))
# print(primes)
_, *N = map(int, open(0).read().split())
ans = 0
for n in N:
    if n > 10000:
        ans += 1
        for p in primes:
            if n % p == 0:
                ans -= 1
                break
    else:
        ans += isp[n]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

o = 0

for i in range(n):

  m = "True"

  a = int(input())

  b = a**0.5

  if a == 2 or a == 3 or a == 5 or a == 7:
    m = "True"

  elif a%2 == 0:
    m = "False"

  else:
    j = 3
    while j <= b:
      if a%j == 0:
        m = "False"
        break
      else:
        j += 1
  if m == "True":
    o += 1

print(o)