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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

Python: import math

def prime_judge(n):
    if n==1:
        return False
    elif n==2:
        return True
    elif n%2==0:
        return False
    else:
        sqrt_num=math.ceil(math.sqrt(n))+1
        for i in range(3,sqrt_num, 2):
            if n%i==0:
                return False
        return True

def prime_count(n):
    count=0
    for i in range(1,n+1):
        if prime_judge(i):
            count+=1
    print(count)

while 1:
    try:
        prime_count(int(input()))        
    except EOFError:
        break

Python: def pri(s,n): 
    tab=[i for i in range(n+1) if s[i] and i>=2]
    return(tab)
 
s=[True for _ in range(999999+1)]
i=2
while i**2<=999999:
    if s[i]:
        j=i*2
        while j<=999999:
            s[j]=False
            j+=i
    i+=1

while True:
    try:
        print(len(pri(s,int(input()))))
    except:
        break

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 = 1 if isPrime[2] else 0
        for i in range(3, n+1, 2):
            if isPrime[i]:
                count += 1
        print(count)
except EOFError:
  pass

Python: import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
 for j in range(2):
  if (s[i],t[i])[j]:
   k=6*i+[5,7][j];n=[i+k,k-i-2]
   s[n[j]::k]=[0]*len(s[n[j]::k])
   t[n[1-j]::k]=[0]*len(t[n[1-j]::k])
for e in map(int,sys.stdin):
 print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3])

Python: def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass
    
if __name__ == '__main__':

    while True:
        try:
            n = int(input())

            ans = primes(n)
            print(len(ans))
            
        except EOFError:
            break

Python: import sys
n = [int(line) for line in sys.stdin]

prime = [0, 0] + [1] * (max(n) - 1)

for i in range(len(prime)):
    if prime[i]:
        for j in range(2 * i, len(prime), i):
            prime[j] = 0

for i in range(1, len(prime)):
    prime[i] += prime[i - 1]

for ni in n:
    print(prime[ni])

Python: while True:
    n = int(input())
    is_prime = [True for i in range(n + 1)]
    is_prime[0] = False
    is_prime[1] = False

    p = 0

    for i in range(2, n + 1):
        if is_prime[i]:
            p += 1
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False

    print(p)

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(int(e)-len([i for i in li[:int(e)+1]if i]))

Python: import sys

def prime(n):
	if n == 2: return True
	if n < 2 or n & 1 == 0: return False
	return pow(2, n-1, n) == 1

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]*((m-1-i*i//2)//i+1)
for e in map(int,sys.stdin):print([e-1,sum(a[:(e+1)//2])][e>3])

Python: import sys
a=[1]*500000
for i in range(3,999,2):
 if a[i//2]:a[(i*i)//2::i]=[0]*len(a[(i*i)//2::i])
for e in map(int,sys.stdin):print([e-1,sum(a[:(e+1)//2])][e>3])

Python: import sys

N = 1000000
lst = [1] * N
for i in range(3, int(N**0.5)+1, 2):
    if lst[i] == 1:
        lst[i*i::2*i] = [0] * len(lst[i*i::2*i])
lst = [2] + [i for i in range(3, N, 2) if lst[i] == 1]
for i in sys.stdin:
    for j in range(len(lst)):
        if lst[j] > int(i):
            print(j)
            break

Python: def prime_checker(n, option = False) -> list:
    p = [False, True, False, False, False, True] * (n // 6 + 1)
    del p[n + 1:]
    p[1 : 4] = False, True, True
    for x in range(5, int(n**.5 + 1)):
        if p[x]:
            p[x * x :: 2*x] = [False] * ((n // x - x) // 2 + 1)
    return [e for e, q in enumerate(p) if q] if option else p

from itertools import accumulate
*c, = map(int, open(0))
*p, = accumulate(prime_checker(max(c)))
for i in c:
    print(p[i])

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


def sieve(ks):
    rejected_set = {x for x in ks for i in range(
        1, x) for j in range(i, x) if i + j + 2 * i * j == x}
    return {2} | {2 * y + 1 for y in (ks - rejected_set)}


def number_of_primes(n):
    return len({p for p in sieve(set(range(1, n + 1))) if p <= n})


def main():
    raw_args = []
    while True:
        try:
            raw_args.append(input())
        except EOFError as e:
            break
    for n in map(int, raw_args):
        print(number_of_primes(n))

if __name__ == "__main__":
    main()

Python: def isprime(x):
    if x == 2:
        return True
    elif x < 2 or x%2 == 0:
        return False
    i = 3
    while i <= pow(x,1/2):
        if x%i == 0:
            return False
        i = i + 2
    return True
import sys
import itertools as it
line = sys.stdin.readlines()
for n in line:
    n = int(n)
    if n == 2:
        print(1)
    else:
        count = 1
        for s in range(3,n+1,2):
            if isprime(s):
                count += 1
    print(count)

Python: from math import sqrt
n = 1000000
l = [1]*n
c = [0]*n
d = 0
l[1]= l[0] = 0
for i in range(4,n,2):
    l[i] = 0
for i in range(9,n,2):
    for j in range(3,int(sqrt(i))+1,2):
        if i % j == 0:
            l[i] = 0
            break
for i in range(n):
    if l[i] == 1:
        d += 1
    c[i] = d
while True:
    try:
        n = int(input())
        print(c[n])
    except:
        exit()

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:
          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 math
while True:
  try:
    n = int(input())
    primes = [1] * (n+1)
    for i in range(2, int(math.sqrt(n))+1):
      if primes[i] == 1:
        for j in range(i*i, n+1, i):
          primes[j] = 0
    print(sum(primes)-2) 
  except EOFError:
    break

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

Python: import sys
import math

N = 1000000
primes = [1] * (N//2+1)
primes[0] = 1

for i in range(3,int(math.sqrt(N))+1,2):
    if primes[i//2]:
        primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
    primes[i//2] += primes[i//2-1]

for i in range(int(math.sqrt(N))+1,N+1,2):
    primes[i//2] += primes[i//2-1]


for i in sys.stdin:
    n = int(i)
    if n == 1:
        print(0)
    elif n == 2:
        print(1)
    else:
        print(primes[(n-1)//2])