Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

Python: import sys,random

rand = random.randint

def prime(n):
	if n == 2:
		return True
	if n < 2 or n & 1 == 0:
		return False
	d = (n-1) >> 1
	while d & 1 == 0:
		d >>= 1
	
	for i in range(10):
		a = rand(1,n-1)
		t = d
		y = pow(a,t,n)
		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

a = [prime(i) for i in range(1000000)]

for s in sys.stdin:
	i = int(s)
	print(a[:i+1].count(True))

Python: import sys
m=500000;a=[1]*m
for i in range(3,999,2):
 if a[i//2]:a[i*i//2::i]=[0]*len(a[i*i//2::i])
p=[]
for i in range(m*2):p+=[i-1 if i<4 else p[i-1]+[0,a[i//2]][i%2]]
for e in sys.stdin:print(p[int(e)])

Python: import sys
from math import sqrt, floor


def is_prime(n):
    for i in range(3, floor(sqrt(n)) + 1, 2):
        if not n % i:
            return False
    return True


def count_prime(input_list):
    count = int(max(input_list) > 1)
    inset = sorted((n, i) for i, n in enumerate(input_list))
    i = 3
    for t in inset:
        t0 = t[0]
        while i <= t0:
            count += is_prime(i)
            i += 2
        yield (t[1], str(count))

for t in sorted(count_prime(list(map(int, sys.stdin)))):
    print(t[1])

Python: import math
def main():
    for _ in range(30):
        try:
            number = int(input())
        except EOFError:
            return None
        p = 0
        for num in range(2, number+1):
            a = int(math.sqrt(num))
            c = 0
            for k in range(2, a+1):
                if num % k == 0:
                    c = 1
                    break
            if c == 0:
                p += 1
        print(p)
    return None


if __name__ == '__main__':
    main()

Python: from math import *
search_list = []
prime_list = []
target = 0
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break
if __name__ == '__main__':
    array = list(get_input())
    for i in range(len(array)):
        for j in range(2,int(array[i])+1):
            search_list.append(j)
        while True:
            if target > sqrt(int(array[i])):
                prime_list = prime_list + search_list
                break
            prime_list.append(search_list[0])
            target = search_list[0]
            search_list.pop(0)
            k = 1
            while target*k<=search_list[-1]:
                if target*k in search_list:
                    search_list.remove(target*k)
                k += 1
        print(len(prime_list))
        target = 0
        k = 0
        del prime_list[:]
        del search_list[:]

Python: from math import sqrt
from sys import stdin
def pm(n):
    l = list(range(3,n+1)[0::2])
    p = 3
    i = 0
    p = l[i]
    m = sqrt(n)+1
    while p <= m:
        l = l[:i+1] + [n for n in l[i+1:] if n%p != 0]
        i += 1
        p = l[i]
    return len(l) + 1

for n in stdin:
    print(pm(int(n)))

Python: # coding: utf-8

LIMIT = 999999

# 1 から LIMIT までのリスト
# 素数（の候補）を 1 、素数でないもを 0 とする  
# 2 以外の偶数は素数ではない
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]

# 3 から LIMIT の平方根までを走査
for i in range(3, int(LIMIT ** 0.5) + 1):
    # 対象が素数である場合
    if prime[i - 1] == 1:
        # 自身の倍数は素数ではない
        for j in range(i ** 2, LIMIT + 1, i):
            # 素数ではないので 0
            prime[j - 1] = 0

while True:
    try:
        n = int(input())
    except EOFError:
        break
    
    # 1 から n までの素数の個数を合計して出力
    print(sum(prime[:n]))

Python: a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
    for j in range(3 * i, 1000000, 2 * i): a[j] = False
    i += 2
 
while True:
    try:
        n = int(input())
    except:
        break
 
    count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
    print(count)

Python: import sys
import math
from array import array

M = 1000000
B = int(math.sqrt(M)+1)//6+1
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = array('I',[1]) * N1
m = array('I',[1]) * N2
i = 5
ini = 4
for p in range(B):
    if l[p] == 1:
        l[p+i::i] = [0] * len(l[p+i::i])
        m[ini-1::i] = [0] * len(m[ini-1::i])
    if m[p] == 1:
        m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
        l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
    i += 6
    ini += 5
 
for i in sys.stdin:
    n = int(i)
    r =  n-1 if n < 3 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
    print(r)

Python: import sys
for ss in sys.stdin:
    s=int(ss)+1
    if s<2:
        print(0)
    else:
        list=[True]*s
        list[0]=False
        list[1]=False
        i=2
        while i**2<=s-1:
            j=i*2
            while j<=s-1:
                list[j]=False
                j+=i
            i+=1
        print(list.count(True))

Python: import math


def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        
        if serial >= sqrt:
            return sum(input_list)

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False


if __name__ == '__main__':
    while True:
        try:
            print(sieve_of_erastosthenes(int(input())))
        except:
            break

Python: def check_prime(goal):
    true_or_false=False
    for i in range(2,goal):
        if goal%i==0:
             true_or_false=True
             break
    if true_or_false==False:
        return True
    else:
        return False

anss=[]
while True:
    try:
        num=int(input())
        num_of_prime=0
        for i in range(2,num+1):
           if check_prime(i):
               num_of_prime+=1
        anss.append(num_of_prime)
    except:
        break

for ans in anss:
    print(ans)

Python: #coding:utf-8
import time
import math
import numpy as np

def flatten(L):
    if isinstance(L, list):
        if L == []:
            return []
        else:
            return flatten(L[0]) + flatten(L[1:])
    else:
        return [L]

def Eratos(data):

    p_list = []
    tmp = []
    num = int(math.sqrt(len(data)))+1
    for i in data:
        i=data[0]
        if i>num:
            break
        else:
            p_list.append(i)
            for j in data:
                if j%i == 0:
                    data.remove(j)
        
    p_list.append(data)
    return p_list

x = int(input())

r_list = list(range(2,(x+1)))
ans = []
ans = Eratos(r_list)

print(len(flatten(ans)))

Python: while True:
    try:
        n=int(input())
    except:
        break
    print(sum(i==2 or pow(2,i-1,i)==1 for i in range(2,n+1)))