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 checkPrime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

if __name__ == "__main__":
    N = input()
    cnt = 0
    for i in range(N):
        n = input()
        if checkPrime(n):
            cnt += 1
    print cnt

Submission status: Accepted

Solution code:
#encoding=utf-8
 
import sys
num = []
ans = []
def 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


for i in sys.stdin:
    inp = map(int , i.split())
    if prime(inp[0]):
        num.append(inp)
num.sort()

for i in xrange(1, len(num)):
    if num[i - 1] != num[i]:
        ans.append(num[i][0])
print len(ans) + 1

Submission status: Accepted

Solution code:
a=input()
def ip(a):
    i=2
    while i**2<=a:
        if a%i==0:return False
        i+=1
    return True
b=0
for i in range(int(a)):
    c=input()
    if ip(int(c)):b+=1
print(str(b))

Submission status: Accepted

Solution code:
c = 0
while True:
    try:
        n = int(input())
    except EOFError:
        break
    c += 1
    for i in range(2, int(n ** 0.5 + 1)):
        if n % i == 0:
            c -= 1
            break
print(c)

Submission status: Accepted

Solution code:
#Prime Numbers ?´???°
c = 0
for i in range(int(input())):
    n = int(input())
    for i in range(2, int(n ** 0.5 + 1)):
        if n % i == 0:
            break
    else:
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-
# ?´???°??????
# ???????????§????????°??????????????????????¢????????´???°?????????????????????????????§????????????
def is_prime(num):
    if num==2 or num==3:
        return True
    for x in xrange(2,int(num**0.5)+1):
        if num%x ==0:
            return False
    return True

count = 0
for i in xrange(input()):
    input_prime_candidate = input()
    if is_prime(input_prime_candidate):
        count+=1
print count

Submission status: Accepted

Solution code:
import math

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

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

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

	return True

if __name__ == '__main__':
	n = int(input())
	A = [int(input()) for i in range(n)]

	cnt = 0
	for i in range(n):
		if isPrime(A[i]) == True:
			cnt = cnt + 1

	print(cnt)

Submission status: Accepted

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

def isPrime(p):
    if p == 2:
        return True
    elif p < 2 or p%2 == 0:
        return False
    elif pow(2, p-1, p) == 1:
        return True
    else:
        return False

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

Submission status: Accepted

Solution code:
import math
A = []
N = int(input())
count = 0
for n in range(N):
    x = int(input())
    if x == 2:
        A.append(x)
        count += 1
    elif x % 2 == 0:
        pass
    elif x > 2:
        for i in range(3, int(math.sqrt(x))+2, 2):
            if x % i == 0:
                break
        else:
            count += 1
            A.append(x)
    
print(count)

Submission status: Accepted

Solution code:
def isPrime(x):
    if x==2:
        return True
    if x<2 or x%2==0:
        return False
    if pow(2,x-1,x)==1:
        return True
    else:
        return False

n=input()
ct=0
for i in xrange(n):
    if isPrime(input()):
        ct+=1
print(ct)

Submission status: Accepted

Solution code:
import math


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

    if n == 2:
        return True

    if n % 2 == 0:
        return False

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


N = int(input())
d = [int(input()) for _ in range(N)]
d.sort()
print([is_prime(x) for x in d].count(True))

Submission status: Accepted

Solution code:
import math
 
 
def is_prime(n):
    global primes
    if n == 1:
        return False
 
    if n == 2:
        return True
 
    if n % 2 == 0:
        return False
 
    s = int(math.sqrt(n))
    for x in range(3, s + 1, 2):
        if n % x == 0:
            return False
    else:
        return True
 
 
N = int(input())
d = [int(input()) for _ in range(N)]
print([is_prime(x) for x in d].count(True))

Submission status: Accepted

Solution code:
from random import randrange

def eratosthenes(size):
    table = [True] * (size + 1)
    table[0] = table[1] = True
    for i in range(2, int(round(pow(size+1, 0.5)))):
        if not table[i]:
            continue
        for j in range(i + i, size+1, i):
            table[j] = False
    return table

def miller_rabin(n, k=20):
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    d = n - 1
    while d & 1 == 0:
        d >>= 1
    for _ in range(k):
        a = randrange(1, n)
        y = pow(a, d, n)
        t = d
        while (t != n - 1) and (y != 1) and (y != n - 1):
            y = pow(y, 2, n)
            t <<= 1
        if (y != n - 1 ) and ((t & 1) == 0):
            return False
    return True

if __name__ == "__main__":
    N = int(input())
    print(sum(map(miller_rabin, [int(input()) for _ in range(N)])))

Submission status: Accepted

Solution code:
from random import randrange


def eratosthenes(size):
    table = [True] * (size + 1)
    table[0] = table[1] = True
    for i in range(2, int(round(pow(size+1, 0.5)))):
        if not table[i]:
            continue
        for j in range(i + i, size+1, i):
            table[j] = False
    return table


def miller_rabin(n, k=20):
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    d = n - 1
    while d & 1 == 0:
        d >>= 1
    for _ in range(k):
        a = randrange(1, n)
        y = pow(a, d, n)
        t = d
        while t != n - 1 and y != 1 and y != n - 1:
            y = pow(y, 2, n)
            t <<= 1
        if y != n - 1 and (t & 1) == 0:
            return False
    return True

if __name__ == "__main__":
    N = int(input())
    print(sum(map(miller_rabin, [int(input()) for _ in range(N)])))

Submission status: Accepted

Solution code:
def isPrime(num):
    if num == 2: return 1
    if num < 2 or num&1 == 0: return 0
    if pow(2, num-1, num) == 1: return 1
    return 0

n = input()
s = 0
for i in xrange(n):
    s += isPrime(input())

print s

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def judge(int):
    if int == 2:return 1
    elif int <= 1 :return 0
    i = 2
    while i*i <= int:
        if int % i == 0:return 0 
        i += 1
    return 1



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

Submission status: Accepted

Solution code:
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())

# # # # # # # # # # # # # # # # # # # # # # # # #

n = input()

cnt = 0

for i in xrange(n):
    m = input()
    for j in xrange(2, int(math.sqrt(m))+1):
        if m % j == 0:
            break
    else:
        cnt += 1

print cnt

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C

import math

num = int(input())

result = 0

while num > 0:
	x = int(input())
	isPrime = 0
	if x == 2:
		isPrime = 1
	elif x < 2 or x % 2 == 0:
		pass
	else:
		i = 3
		isPrime2 = 1
		while i <= math.sqrt(x):
			if x % i == 0:
				isPrime2 = 0
				break
			i = i + 2
		if isPrime2:
			isPrime = 1
	if isPrime:
		result += 1
	num -= 1

print(result)

Submission status: Accepted

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

def is_prime(n):
    if n == 2:
        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 not composite(d,n,s)

r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
      if n not in r:
          r.append(n)

print(len(r))

Submission status: Accepted

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

def is_prime(n):
    if n==2:
        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 not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
      if n not in r:
          r.append(n)

print(len(r))

Submission status: Accepted

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

def is_prime(n):
    if n==2:
        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 not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
      if n not in r:
          r.append(n)

print(len(r))

Submission status: Accepted

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

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 not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
      if n not in r:
          r.append(n)

print(len(r))

Submission status: Accepted

Solution code:
def isPrime(n):
    if n==2 or n==3:
        return True
    elif n%2==0:
        return False
    else:
        i = 2
        while i**2 <= n:
            if n%i == 0:
                return False
            i += 1
    return True
    
r = []
n = int(input())
for i in range(n):
    p = int(input())
    if isPrime(p):
        if p not in r:
            r.append(p)

print(len(r))

Submission status: Accepted

Solution code:

N=int(raw_input())
s=[int(raw_input()) for x in range(N)]


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

a=filter(is_prime,s)
print len(a)

Submission status: Accepted

Solution code:
def composite(d,n,s):
    for a in (2,3,5,7):
        p = False
        if pow(a,d,n) == 1:
            continue
        for i in range(s):
            if pow(a, 2**i * d, n) == n-1:
                p = True
                break
        if not p:
            return True
    return False
 
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 not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
    r.append(n)
 
print(len(r))

Submission status: Accepted

Solution code:
def composite(d,n,s):
    for a in (2,3,5,7):
        p = False
        if pow(a,d,n) == 1:
            continue
        for i in range(s):
            if pow(a, 2**i * d, n) == n-1:
                p = True
                break
        if not p:
            return True
    return False
  
def is_prime(n):
    if n in (2,3,5,7):
        return True
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n):
    r.append(n)
  
print(len(r))

Submission status: Accepted

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


def is_prime(number):
    if number == 2:
        return True
    elif number < 2 or number % 2 == 0:
        return False
    else:
        i = 3
        while i <= pow(number, 0.5):
            if number % i == 0:
                return False
            i += 2
        return True


if __name__ == '__main__':
    N = input()
    numbers = [input() for i in xrange(N)]
    count = 0
    for i in xrange(len(numbers)):
        if is_prime(numbers[i]):
            count += 1
    print count

Submission status: Accepted

Solution code:
import sys
import math


prime_numbers = [2, 3, 5, 7]

def prime_numbers_under(num):
  global prime_numbers

  prime_number_max = max(prime_numbers)
  if prime_number_max > num:
    return prime_numbers

  for i in range(prime_number_max + 1, num + 1):
    check_max = math.floor(math.sqrt(i))
    for j in prime_numbers:
      if j <= check_max:
        if i % j == 0:
          break
    else:
      prime_numbers.append(i)

  return prime_numbers

def main():
  amount = 0

  length = int(input())
  for _ in range(0, length):
    i = int(input())
    check_max = math.floor(math.sqrt(i))
    for j in prime_numbers_under(check_max):
      if j <= check_max:
        if i % j == 0:
          break
    else:
      amount += 1

  print(amount)
  return 0


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math
def isprime(x):
  if x == 2:
    return True

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

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

  return True


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

print(count)

Submission status: Accepted

Solution code:
import math


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:
    check_max = math.ceil(math.sqrt(n))
    for i in range(2, check_max + 1):
      if n % i == 0:
        return False
    else:
      return True

def main():
  primes = set([])
  length = int(input())
  for _ in range(0, length):
    n = int(input())
    if is_prime(n):
      primes.add(n)

  print(len(primes))
  return 0


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def prime(num):
    if num == 0:
        return False
    elif num == 1:
        return False
    elif num == 2:
        return True
    i = 2
    while True:
        if i**2 > num:
            break
        if num%i==0:
            return False
        i += 1
    return True
n = int(raw_input())

nums = []
for _ in range(n):
    a = int(raw_input())
    nums.append(a)

ret = 0
for num in nums:
    if prime(num):
        ret += 1
print ret

Submission status: Accepted

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

N = input()
print sum(is_prime(input()) for i in range(N))

Submission status: Accepted

Solution code:
def prime_numbers(n):
    cnds = [True] * n
    for x in xrange(2, int(n**0.5 + 1)):
        if cnds[x]:
            for m in xrange(2*x, n, x):
                cnds[m] = False
    return [i for i in xrange(2, n) if cnds[i]]

def is_prime(n):
    return all(n % m for m in primes if m < n)

primes = prime_numbers(10**4)
N = input()
print sum(is_prime(input()) for i in range(N))

Submission status: Accepted

Solution code:
from math import sqrt
def prime(n):
    if n == 2:
        return True
    elif n < 2 or n % 2 == 0:
        return False
    else:
        i = 3
        while i <= sqrt(n):
            if n % i == 0:
                return False
            i += 2
    return True

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

print(c)

Submission status: Accepted

Solution code:
# coding: utf-8

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
primenum =int(input())
ans = 0
for p in range(primenum):
    targ = int(input())
    for t in range(2,math.floor(math.sqrt(targ)) + 1):
        if targ % t == 0:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def isPrime(n):
    i = 2
    while i*i <= n:
        if n % i == 0:
            return False
        i += 1
    return True
    
n = int(input())
ans = 0

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

Submission status: Accepted

Solution code:
import sys,math

def is_prime_number(arg):
    arg_sqrt=int(math.floor(math.sqrt(arg)))
    i=2
    while i <=arg_sqrt:
        if arg %i ==0:
            return False
        i+=1

    return True
        
        
n=0
prime_numbers=0
for line in sys.stdin:
    l=int(line)
    if n == 0:
        n=l
        continue

    if is_prime_number(l):
        prime_numbers+=1
        

print prime_numbers

Submission status: Accepted

Solution code:
import math
def is_prime(x):
    if x == 2:
        return True
    if (x % 2 == 0):
        return False
    m = math.ceil(math.sqrt(x))
    for i in range(3, m + 1):
        if x % i == 0:
            return False
    return True


n = int(input())

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

print(prime)

Submission status: Accepted

Solution code:
import sys
import math

def is_prime_number(num):
    if num == 2:
        return True
    
    if num == 1 or num % 2 == 0:
        return False

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

    return True

def main():
    n = int(sys.stdin.readline().strip())
    sum = 0
    for _ in range(n):
        num = int(sys.stdin.readline().strip())
        if is_prime_number(num):
            sum += 1

    print(sum)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def getprimes(n):
  primes = []
  for i in xrange(2, n+1):
    isprime = True
    for j in xrange(len(primes)):
      if i % primes[j] == 0:
        isprime = False
        break
    if isprime:
      primes.append(i)
  return primes

n = int(raw_input())
primes = getprimes(10000)
count = 0
for _ in xrange(n):
  x = int(raw_input())
  isprime = True
  for i in xrange(len(primes)):
    if primes[i] >= x:
      break
    if x % primes[i] == 0:
      isprime = False
      break
  if isprime:
    count += 1
print count

Submission status: Accepted

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

def is_prime(q):
    if q == 2:
        return True
    if q < 2:
        return False
    return pow(2, q-1, q) == 1


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

Submission status: Accepted

Solution code:
#coding:UTF-8
import math
def Count(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+=2
    return 1

def PN(n,a):
    count=0
    for i in range(n):
        count+=Count(a[i])
    print(count)
    
if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    PN(n,a)

Submission status: Accepted

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

N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
counter = 0
for i in range(0, N):
    if isprime(A[i]):
        counter += 1
        
print(counter)

Submission status: Accepted

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


for i in range(int(n)):
    x = int(input())
    if x == 1:
        x = 0
    for j in range(2,math.floor(math.sqrt(float(x)))+ 1):
        if x % j == 0:
            x = 0
            break
    if x != 0:
        c += 1	
print(c)

Submission status: Accepted

Solution code:
import math

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

        
        

p = 0
n = int(input())

for i in range(n):
    if prime(int(input())) == True:
        p += 1
        

print(p)

Submission status: Accepted

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

n = int(input())
ret = 0
while n:
    x = int(input())
    if is_prime(x): ret += 1
    n -= 1

print(ret)

Submission status: Accepted

Solution code:
import sys
import math

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

input = []
for line in sys.stdin:
     input.append(int(line))
##input = [2, 4, 7, 1, 2, 3, 1, 11, 4576435353, 2342342]
count = 0
for num in set(input):
     if isPrime(num):
          count += 1

print count

Submission status: Accepted

Solution code:
ans = 0
for i in xrange(input()):
    n = int(raw_input())
    if n <= 1:
        continue
    j = 2
    while j*j <= n:
        if n%j == 0:
            break
        j += 1
    else:
        ans += 1
print ans

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp
#?´???°??????
#x????´???°y???2 < y < sqrt(x)??????????????¨??????

from math import sqrt,ceil

def check_prime_number(n):
    sqrt_num = ceil(sqrt(n))
    
    if n == 2:
        return True
    elif n < 2:
        return False
    elif (n % 2) == 0:
        return False
    div = 3
    while div <= sqrt_num:
        if (n % div) == 0:
            return False
        div += 2
        
    return True

def count_prime_numbers(n_list):
    ans = 0
    for n in n_list:
        if check_prime_number(n):
            ans += 1
    return ans

def main():
    num = int(input())
    target_list = [int(input()) for i in range(num)]
    print(count_prime_numbers(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp
#?´???°??????
#x????´???°y???2 < y < sqrt(x)??????????????¨??????

from math import sqrt,ceil

def check_prime_number(n):
    sqrt_num = ceil(sqrt(n))
    
    if n == 2:
        return True
    elif n < 2 or (n % 2) == 0:
        return False

    div = 3
    while div <= sqrt_num:
        if (n % div) == 0:
            return False
        div += 2
        
    return True

def count_prime_numbers(n_list):
    ans = 0
    for n in n_list:
        if check_prime_number(n):
            ans += 1
    return ans

def main():
    num = int(input())
    target_list = [int(input()) for i in range(num)]
    print(count_prime_numbers(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import sqrt
def isprime(inlst, i, sq):
    while sq >= i:
    	inlst = [x for x in inlst if x%i > 0 or x == i]
    	i += 2
    return inlst
n = int(input())
inlst = []
for i in range(n):
    inlst.append(int(input()))
inlst = [x for x in inlst if x%2 > 0 or x == 2]
i = 3
maxin = max(inlst)
inlst = isprime(inlst, i, int(sqrt(maxin)) + 1)
print(len(inlst))

Submission status: Accepted

Solution code:
from math import sqrt
def isprime(inlst, chk, sq):
	for i in range(3, sq, 2):
		inlst = [x for x in inlst if x%i > 0 or x == i]
		i += 2
	return inlst
n = int(input())
inlst = [input() for i in range(n)]
inlst = [int(i) for i in inlst]
inlst = [x for x in inlst if x%2 > 0 or x == 2]
inlst = isprime(inlst, 3, int(sqrt(max(inlst))) + 1)
print(len(inlst))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

def prime_number(num):
    if num == 2:
        return 1
    elif num%2 != 0:
        for j in range(3, int(math.sqrt(num))+1, 2):
            if num%j == 0:
                return 0
        return 1
    else:
        return 0

n = int(raw_input())

count = 0
for i in range(n):
    num = int(raw_input())
    if prime_number(num) == 1:
        count += 1

print count

Submission status: Accepted

Solution code:
def is_prime(num):
    """ ??°???????´???°????????????????????????
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_C
    :param num: ?????????????????°???
    :return: num????´???°??§????????°True
    """
    if num == 2:
        return True
    if num < 2 or num % 2 == 0:
        return False

    i = 3
    while i <= num**0.5:
        if num % i == 0:
            return False
        i += 2
    return True


if __name__ == '__main__':
    # ??????????????\???
    data = []
    num = int(input())
    for i in range(num):
        data.append(int(input()))
    # data = [6, 2, 3, 4, 5, 6, 7]

    # ?´???°????????°?????????
    num_of_prime = 0
    for d in data:
        if is_prime(d):
            num_of_prime += 1

    # ???????????????
    print('{0}'.format(num_of_prime))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
primes=[]
def getprime():
    for i in range(2,10000):
        ok=True
        for p in primes:
            if i%p==0:
                ok=False
        if ok:
            primes.append(i)

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

getprime()
n=int(input())
ns=[]
ans=0
for i in range(n):
    a=int(input())
    if check(a):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""
input:
11
7
8
9
10
11
12
13
14
15
16
17

output:
4
"""

import sys
import math


def is_prime(x):
    if x == 2:
        return True
    elif x < 2 or not x % 2:
        return False

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

    return True


def solve(_c_list):
    cnt = 0
    for ele in _c_list:
        if is_prime(ele):
            cnt += 1
    return cnt


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_num = int(_input[0])
    c_list = list(map(int, _input[1:]))
    ans = solve(c_list)
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""
input:
11
7
8
9
10
11
12
13
14
15
16
17

output:
4
"""

import sys


def is_prime(x):
    if x == 2:
        return True
    elif x < 2 or not x % 2:
        return False

    return pow(2, x - 1, x) == 1


def solve(_c_list):
    cnt = 0
    for ele in _c_list:
        if is_prime(ele):
            cnt += 1
    return cnt


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_num = int(_input[0])
    c_list = list(map(int, _input[1:]))
    ans = solve(c_list)
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""
input:
11
7
8
9
10
11
12
13
14
15
16
17

output:
4
"""

import sys
import math


def is_prime(n):
    if n == 2:
        return True
    elif n < 2 or not n % 2:
        return False

    i = 3
    n_sqrt = math.sqrt(n)
    while i <= n_sqrt:
        if not n % i:
            return False
        i += 2
    return True


def solve(_c_list):
    cnt = 0
    for ele in _c_list:
        if is_prime(ele):
            cnt += 1
    return cnt


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_num = int(_input[0])
    c_list = list(map(int, _input[1:]))
    ans = solve(c_list)
    print(ans)