Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

Python: import bisect
def ifprime(n):
    for i in range(3,int(n**0.5)+1):
        if n%i==0:return(False)
    return(True)
prime_list=[2,3]
while 1:
    try:
        n=int(input())
        if n>prime_list[-1]+1:
            for i in range(prime_list[-1]+2,n+1,2):
                if ifprime(i):prime_list.append(i)
        x=bisect.bisect_left(prime_list,n+1)    
        print(x)
    except:break

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: import sys


def primes(n):
    f = []
    for i in range(n + 1):
        if i > 2 and i % 2 == 0:
            f.append(0)
        else:
            f.append(1)
    i = 3
    while i * i <= n:
        if f[i] == 1:
            j = i * i
            while j <= n:
                f[j] = 0
                j += i + i
        i += 2
    return f[2:]


if __name__ == "__main__":
    ps = primes(100)
    for n in sys.stdin:
        i = int(n)
        if i < 2:
            print(0)
            break
        print(i,sum(ps[:i-1]))

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

Python: while 1:
    try:
        b=[]
        count=1
        x=int(input())
        if x==1:
            print(0)
        elif x==2:
            print(1)
        else:
            for i in  range(3,x+1):
                count1=0
                for j in range(2,i):
                    if i%j==0:
                        count1=1
                        break
                if count1==0:
                    count+=1
            print(count)        
    except EOFError:
        break

Python: import sys
import math

N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])

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

for i in sys.stdin:
        n = int(i)
        print(sum(primes[0:n+1]))

Python: while True:
 try:
  n=int(input())
  L=[i for i in range(n+1) if i==2 or (i>=3 and i%2==1)]
  print(len(L))
 except EOFError:
  break

Python: from math import sqrt
from sys import stdin
def isprime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(sqrt(n))+1):
        if n % i == 0:
            return False
    return True

for n in stdin:
    n = int(n)
    ct = 0
    for i in range(1,n + 1):
        if isprime(i):
            #print (i)
            ct += 1
    print (ct)

Python: num = []
while True:
    try:
        num.append(int(input()))
    except EOFError:
        break

lst = [i for i in range(2, max(num)+1)]
for i in lst[::-1]:
    for j in range(2, i):
        if i % j == 0:
            lst.pop(lst.index(i))
            break

for i in num:
    for j in lst:
        if i < j:
            print(lst.index(j))
            break
        elif i == j:
            print(lst.index(j)+1)
            break

Python: def ct(num):
    primel=[2]
    for i in range(num):
        n=i+1
        if i==0 or i==1:continue 
        for e in primel:
            if n%e==0:break
        else:primel.append(n)
    return len(primel)        
    
while True:
    try:raw=[int(i) for i in input().split(" ")]
    except:break
    a=raw[0]
    print(str(ct(a)))

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

Python: from itertools import takewhile
primes = [2, 3, 5, 7]
append_prime = primes.append
upper = 10


def is_prime(num):
    for p in primes:
        if num % p == 0:
            return False
    return True


def calc_prime(num):
    for i in range(upper + 1, num + 1):
        if is_prime(i):
            append_prime(i)

for s in sys.stdin:
    print(primes)
    n = int(s)
    if upper < n:
        calc_prime(n)
        upper = n
        print(len(primes))
    else:
        print(len(tuple(takewhile(lambda x: x <= n, primes))))

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

Python: import sys
m=10**6;a=[0,0]+[1]*m
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 bisect

primes = [0, 0] + [1] * 999999
for i in range(2, 1000):
    if primes[i]:
        for j in range(i*i, 1000000, i):
            primes[j] = 0

primes = [i for i, v in enumerate(primes) if v]
while True:
    try:
        n = int(input())
    except:
        break
    print(bisect.bisect(primes, n))

Python: import sys

l = [True] * 100000
for i in range(2, 100000):
    if (l[i - 1]):
        for j in range(i ** 2 - 1, 100000, i):
            l[j] = False
n = [int(line) for line in sys.stdin]
for j in n:
    print(l[1:int(j)].count(True))

Python: import math

isPrime = [True] * 1000000
primes = []
def eratos(n):
    isPrime[0] = isPrime[1] = False
    for i in range(2,int(math.sqrt(n))):
        if isPrime[i]:
            j = 2 * i
            while j <= n:
                isPrime[j] = False
                j = j + i
eratos(999999)

while True:
    try:
        num = int(input())
        ans = 0
        for i in range(0,num + 1):
            if isPrime[i]:
                ans += 1
        print(ans)
    except:
        break

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

for input in sys.stdin:
    prime_num = 0
    for i in range(int(input)):
        y = i+1
        x = y / 2
        while x > 1:
            if y % x == 0:
                break
            x -= 1
        else:
            prime_num += 1
    print(prime_num-1)

Python: from math import sqrt

I_list=[]

#input syutoku

while True:

	try:

		k=int(input())

		I_list.append(k)

	except:

		break



I_max=max(I_list)

#create list (I_max=100 -> [3,5,7,...,99])

odd_list=[x for x in range(3,I_max+1,2)]

#print(W_list)



P_list=[2]



p=0

#print(I_list)

ct=0

while p<=int(sqrt(I_max)):

	p=odd_list.pop(0)

	P_list.append(p)

	P_baisuu=[p*x for x in range(1, int(I_max/p) +1 )]

	K_list=set(odd_list)-set(P_baisuu)

	odd_list=sorted(list(K_list))

#	print("P_list=")

#	print(P_list)

#	print("odd_list=")

#	print(odd_list)



prime_list=P_list+odd_list

#print("prime_list=")

#print(prime_list)



for i in I_list:

	w=[j for j in prime_list if j<=i ]

	print(len(w))

Python: def so(x):
    a=[]
    b=[True]*(n+1)
    b[0]=False
    b[1]=False
    for i in range(2,int(x**0.5)+1):
        if not b[i]:
            continue
        for j in range(i*2,n+1,i):
            b[j]=False
    for k in range(len(b)):
        if b[k]:
            a.append(k)
    print(len(a))
while True:
    try:
        n = int(input())
    except:
        break
    so(n)