Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

Python: from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(n):
    if n < 2:
        return []
    if n == 2:
        return [2]
    L = list(range(2, n + 1))
    PL = []
    while True:
        PL.append(L[0])
        L = [i for i in L if i % PL[-1] != 0]
        if L[-1] < PL[-1] ** 2:
            return PL + L

primelist = enum_prime(999999)
for line in stdin:
    n = int(line)
    cnt = 0
    for p in primelist:
        if n < p:
            break
        cnt += 1
    print(cnt)

Python: LIMIT = 10000000
 
isPrime = [True for _ in range(LIMIT)]

isPrime[0] = isPrime[1] = False
 
for i in range(2, int(LIMIT ** 0.5)+1):
  if isPrime[i]:
    for j in range(i * i, LIMIT, i):
      isPrime[j] = False
 
try:
    while True:
        n = int(input())

        count = 0
        if n >= 2:
            count = 1

        for i in range(3, n+1, 2):
            if isPrime[i]:
                count += 1

        print(count)
except EOFError:
  pass

Python: import sys
import math as mas

def sieve(n):
	p=[True for i in range(n+1)]
	p[0]=p[1]=False
	end=int(n**0.5)
	for i in range(2,end+1):
		if p[i]:
			for j in range(i*i,n+1,i):
				p[j]=False
	return p
	
sosu=sieve(1000010)
for i in sys.stdin:
	print(sum(sosu[t] for t in range(int(i)+1)))

#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Python: import sys


def prime(x):
    for i in p_list:
        if x % i == 0:
            return 0
    return 1


if __name__ == "__main__":
    a = 10000
    i = 2
    p_list = []
    while i < a:
        if prime(i):
            p_list.append(i)
        i += 1
    print(p_list)

    for i in sys.stdin:
        n = int(i)
        while 1:
            if n not in p_list:
                n -= 1
            else:
                print(p_list.index(n) + 1)

Python: import sys
#from me.io import dup_file_stdin

N=1000000
primes = [1]*N
primes[0:2]=[0,0,1]

for i in range(2,N):
    if primes[i]==1:
        j=i+i
        while j<=N:
            primes[j]=0
            j+=i

#@dup_file_stdin
def solve():
    for query in map(int,sys.stdin):
        print(sum(primes[2:query+1]))
solve()

Python: from math import *
search_list = []
search_list_ref = []
prime_list = []
prime_list_ref = []
target1,target2,num = 0,0,2
i,j,k = 0,0,0
flag = 0
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break
if __name__ == "__main__":
    array = list(get_input())
    #print("/*------------------------------------*/")
    for i in range(len(array)):
        #print(str(array[i]) + "?????????????´???°????±??????????")
    #??\????????¨?????????????????????????????§?´???°????????°?????¢?´¢??????
        #?????????sqrt(int(array[i]))?????§????????§?´???°??????????????????
        ref_target = int(sqrt(int(array[i])))
        search_list_ref.append(2)
        search_list_ref.append(ref_target)
        while target1 < ref_target:
            if search_list_ref == []:
                break
            prime_list_ref.append(search_list_ref[0])
            target1 = search_list_ref[0]
            search_list_ref.remove(target1)
            if target1 > ref_target:
                break
            num = target1
            if target1 == 2:
                for num in range(2,ref_target):
                    if (num % target1 != 0):
                        search_list_ref.append(num)
                if ref_target != 3:
                        search_list_ref.remove(ref_target)
            else:
                for j in search_list_ref:
                    if j % target1 == 0:
                        search_list_ref.remove(j)

        prime_list_ref = prime_list_ref + search_list_ref
        search_list.append(2)
        search_list.append(int(array[i]))

        #?????????????????¬??\?±????????????°?????????????´???°????±??????????
        while target2 < sqrt(int(array[i])):
            prime_list.append(search_list[0])
            target2 = search_list[0]
            search_list.remove(target2)
            if target2 > sqrt(int(array[i])):
                break
            num = target2
            if target2 == 2:
                for num in range(2,int(array[i])):
                    for k in prime_list_ref:
                        if num % k != 0:
                            flag = 1
                        else:
                            flag = 0
                            break
                    if flag == 1:
                        search_list.append(num)
                search_list.remove(int(array[i]))
                prime_list_ref.pop(0)
                search_list[1:1] = prime_list_ref
            elif target2 not in prime_list_ref:
                for j in search_list:
                    if j % target2 == 0:
                        search_list.remove(j)
            else:
                pass
        prime_list = prime_list + search_list
        print(str(len(prime_list)))
        del search_list_ref[:]
        del prime_list_ref[:]
        del search_list[:]
        del prime_list[:]
        target1 = 0
        target2 = 0
        #print("/*------------------------------------*/")

Python: import sys
a=[0,0]+[1]*10**6
for i in range(999):
 if a[i]:a[i*2::i]=[0 for j in a[i*2::i]]
for e in sys.stdin:print(sum(a[:int(e)+1]))

Python: import sys

def prime(n):
    a = [0] * (n + 1)
    a[0] = 1
    a[1] = 1
    i = 2
    while n // i >= i:
        if a[i] != 0:
            i += 1
            continue
        j = 2 * i
        while j <= n:
            a[j] = 1
            j += i
        i += 1
    return [i for i, ai in enumerate(a) if ai == 0]

for i in sys.stdin:
    print(len(prime(int(i))))

Python: isPrime = [True] * 1000000
prime = [0, 0]
def calcPrime():
    isPrime[0] = isPrime[1] = False
    count = 0
    for i in range(2, len(isPrime)):
        if(isPrime[i]):
            count += 1
            prime.append(count)
            for j in range(2 * i, len(isPrime), i):
                isPrime[j] = False
        else:
            prime.append(count)

calcPrime()
while(True):
    try:
        n = input()
        print(prime[n])
    except Exception:
        break

Python: import sys

values = []
for line in sys.stdin:
    values.append(int(line))

for val in values:
    prime = 0
    i = 2
    while i <= val:
        j = 2
        while j <= i:
            if i % j == 0:
                if j == i:
                    prime += 1
                else:
                    break
            j += 1
        i += 1
    print(prime)

Python: import math
def pri(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

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

l=[i for i in range(110000)if pri(i) ]

while True:
    n = int(input())
    if n == 0: break
    print(sum(l[:n]))