Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

Python: # -*- coding:utf-8 -*-
import sys

# n??\???????´???°?????°?????????
def prime(n):
    l = range(0,n+1)
    i,k = 0,2
    result = 1

    if n >= 3:
        prime_nums = [2, 3]
    else:
        prime_nums = []

    while i <= n:
        while l[i] > k:
            result = l[i]%k
            k = k+1
            if result == 0:
                break
            if (l[i]-1 == k) and (result != 0):
                prime_nums.append(l[i])

        i, k = i+1, 2

    #return prime_nums
    return len(prime_nums)

while True:
    try:        
        psum = prime(int(input()))
        print(psum)
    except:
        break

Python: import sys
  
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
  
for i in range(3,int(N**0.5),2):
    if primes[i//2]:
        primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
  
for i in sys.stdin:
    n = int(i)
    if n < 3:
        print(n-1)
    else:
        print(sum(primes[:(n+1)//2])+1)

Python: def mk_table(n):
    res = [1] * (n + 1)
    res[:2] = 0, 0

    for i in range(2, n):
        if i ** 2 > n:
            break

        if res[i] == 1:
            for j in range(i*2, n // i + 1, i):
                res[j] = 0

    return res


tbl = mk_table(999999)
try:
    while 1:
        print(len([x for x in tbl[:int(input())+1] if x == 1]))
except Exception:
    pass

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 = 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))


print('\n'.join(t[1] for t in sorted(count_prime(list(map(int, sys.stdin))))))

Python: import sys
import math
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 = [1] * N1
m = [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

primes = [2]
for line in sys.stdin:
  try:
    n = int(line)
    if n > max(primes):
      for i in range(max(primes) + 1, n + 1):
        if i % 2 == 0 or i % 3 == 0:
          continue
        primes.append(i)
        for p in primes:
          if i % p == 0 and i != p:
            primes.pop()
            break
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break

Python: import sys

def prime(maximum):
    sieve = [True] * (maximum + 1)

    def sieved(prime):
        for not_prime in range(prime + prime, len(sieve), prime):
            sieve[not_prime] = False

    sieve[0] = sieve[1] = False
    sieved(2)
    for x in range(3, int(maximum ** 0.5) + 1, 2):
        if sieve[x]: sieved(x)
    return [prime for prime, is_prime in enumerate(sieve) if is_prime]

count = 0
numbers = []
for line in sys.stdin:
    numbers.append(int(line))
    count += 1

counts = []
for i in range(count):
    counts.append(0)

for prime in prime(1000000):
    if prime > 999999:
        break
    for i in range(count):
        if prime <= numbers[i]:
            counts[i] += 1

for count in counts:
    print(count)

Python: def solve(n):
	A=[0 for i in range(n+1)]
	A[2]=1
	for i in range(2,n+1):
		cnt=0
		for j in range(1,i+1,2):
			if i%j==0:
				cnt+=1
		if cnt==2:#1??¨????????°??????
			A[i]=1
	return sum(A) 

while True:
	try:
		n = int(input())
		print(solve(n))
	except EOFError:
		break

Python: LIMIT = 999999

prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]

for i in range(3, LIMIT + 1):
    if prime[i - 1]:
        for j in range(i ** 2, len(prime), i):
            prime[j - 1] = 0

while True:
    try:
        n = int(input())
    except EOFError:
        break
    
    print(n, sum(prime[:n]))

Python: def mk_table(n):
    res = [1] * (n + 1)
    res[:2] = [0, 0]

    for i in range(2, n):
        if i ** 2 > n:
            break

        if res[i] == 1:
            j = 2
            while i * j <= n:
                res[i * j] = 0
                j += 1

    return res


tbl = mk_table(999999)
try:
    while 1:
        print(len([x for x in tbl[:int(input())+1] if x == 1]))
except Exception:
    pass

Python: MAX = 1000000
SQRT = 1000     # sqrt(MAX)
 
prime = [0] * MAX
 
def sieve():
    for i in range(3, MAX, 2):
        prime[i] = 1
    for i in range(3, SQRT, 2):
        if prime[i] == 1:
            for j in range(i*i, MAX, i):
                prime[j] = 0
 
sieve()
cnt = [0] * (MAX+1)
cnt[2] = f = 1
for i in range(3, MAX, 2):
    if prime[i]:
        f += 1;
    cnt[i] = cnt[i+1] = f
     
while True:
    try:
        print(cnt[int(input())])
    except EOFError:
        break

Python: def is_prime(x):
    x=abs(x)
    if x==2:
        return True
    if x<2 or x&1==0:
        return False
    return pow(2,x-1,x)==1
while True:
    try:
        n=int(input())
    except:
        break
    print(sum(is_prime(i)==True for i in range(2,n+1)))

Python: # -*- coding;utf-8 -*-

def sieve(n):
    p = 0
    primes = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if(is_prime[i]):
            primes.append(i)
            p += 1
            for j in range(i*2,n,i):#iごとに増える
                is_prime[j] = False
    return p

if(__name__ == "__main__"):
    while(True):
        try:
            n = int(input())
        except:
            break
        print(sieve(n) + "\n")

Python: import sys
def main():
    for line in sys.stdin:
        n = int(line)
        hoge = [i for i in range(2, n + 1) if i % 2 != 0 or i == 2]
        fuga = [2]
        for i in range(1, len(hoge)):
            cnt = 0
            for j in range(i):
                if hoge[i] % hoge[j] != 0:
                    cnt += 1
            if cnt == i:
                fuga.append(hoge[i])
        print(len(fuga))


if __name__ == "__main__":
    main()

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

Python: while True:
    try:
        M = int(input())
    except EOFError:
        break
    N = (M+1)//2-1
    temp = [i for i in range(1, N+1)]
    for j in range(1,(N-1)//3+1):
        for i in range(1,j+1):
            if i+j+2*i*j>N:
                break
            try:
                temp.remove(i+j+2*i*j)
            except ValueError:
                pass
    print(len(temp)+1)

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]))