Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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 input_list

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


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

        if 5 >= n:
            print(1)

        else:
            input_list = sieve_of_erastosthenes(n)

            print(sum(input_list))

Python: from math import sqrt, ceil

N = 1000000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))

while True:
    try:print(len([1 for _ in temp[:int(input())+1] if _]))
    except:break

Python: import math
def isPrime(x):
	if x == 2:
		return True
	elif x < 2 or x % 2 == 0:
		return False
	else:
		i = 3
		while i in range(math.sqrt(x)):
			if x % i == 0:
				return False
			i += 2
		return True

import sys
dataset = sys.stdin.readlines()
for n in dataset:
	n = int(n)
	counter = 0
	for i in range(n+1):
		if isPrime(i):
			counter += 1
	print(counter)

Python: # ?´???°?????°?????¨?????????????????°??????

import sys
import math

prim_no = {}                    # ????????°????´???°??§??????????????????????????????

def is_prime(no):
    if no == 2:
        return True
    
    if no % 2 == 0:
        return False

    if prim_no.get(no) is not None:
        return prim_no.get(no)

    max_check = int(math.sqrt(no))
    for i in range(3, max_check+1):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

def main():
    while True:
        num = sys.stdin.readline()
        if num is None or num.strip() == '':
            break

        num = int(num.strip())
        cnt = 0
        for i in range(2, num + 1):
            if is_prime(i):
                cnt += 1

        print(cnt)

if __name__ == '__main__':
    main()

Python: def eratosthenes(N):
    prime=[]
    a=[2]+list(range(3,N+1,2))
    end=N**0.5
    while len(a) and a[0]<=end:
        nn=a.pop(0)
        prime.append(nn)
        a=[i for i in a if i%nn!=0]
    prime+=a
    return prime
while True:
    try:
        n=int(input().strip())
        print(len(eratosthenes(n)))
    except:
        break

Python: import sys

primes = [2]
for line in sys.stdin:
  try:
    n = int(line)
    for i in range(max(primes) + 1, n + 1):
      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: from math import sqrt,floor
from sys import stdin

def cntPrime(n):
    mx = sqrt(n)
    if n % 2 == 0:
      l = [0, 1] + [1, 0] * (int(n/2) - 1)
    else:
      l = [0, 1] + [1, 0] * (int(n/2) - 1) + [1]
    c = 3
    while c < mx:
        for k in range(c*2, n+1, c):
            l[k-1] = 0
        c = l[(c+1):].index(1) + c +2
        while c % 2 == 0:
            c = l[(c+1):].index(1) + c +2
    return sum(l)
for n in stdin:
    n = int(n)
    print(cntPrime(n))

Python: import sys

N = []
ns = sys.stdin.readlines()
for n in ns:
    N.append(int(n))
ml = max(N)
P = [2]
for x in range(2, ml+1):
    flag = True
    for d in P:
        flag = flag and (x % d != 0)
    if flag == True:
        P = P + [x]
for m in N:
    print(len([p for p in P if p<=m]))

Python: from math import sqrt,floor
from sys import stdin

def cntPrime(n):
    mx = sqrt(n) + 1
    l = [0] + [1] * (n - 1)
    c = 2
    while c < mx:

        for k in range(2, floor(n/c) + 1):
            l[c * k -1] = 0
        c = l[:c].index(1) + c
    return sum(l)
for n in stdin:
    n = int(n)
    print(cntPrime(n))

Python: from math import sqrt,floor
from sys import stdin

def cntPrime(n):
    mx = sqrt(n)
    if n % 2 == 0:
      l = [0, 1] + [1, 0] * (int(n/2) - 1)
    else:
      l = [0, 1] + [1, 0] * (int(n/2) - 1) + [1]
    c = 3
    while c < mx:
        for k in range(c*2, n+1, c):
            l[k-1] = 0
        c = l[(c+1):].index(1) + c +2
        while c % 2 == 0:
            c = l[(c+1):].index(1) + c +2
    return l
t = cntPrime(1000000)
for n in stdin:
    n = int(n)
    print(sum(t[:n-1]))

Python: import bisect
import sys
n = 1000000
primes = {i for i in range(3, n, 2)}
for i in range(3, 1000, 2):
    s = {j for j in range(i*2, n, i)}
    primes -= s

primes = [2] + sorted(primes)
for l in sys.stdin:
    print(bisect.bisect(primes, int(l)))

Python: import sys
import math
#from me.io import dup_file_stdin

primes = [2,3,5,7]

def isPrime(x):
    if x<=primes[-1]:
        return x in primes
    else:
        for prime in primes:
            if x%prime==0:
                return False
        else:
            current=primes[-1]
            dst=math.sqrt(x)
            while current<dst:
                if(x%current==0):
                    return False
            else:
                return True

#@dup_file_stdin
def solve():
    for query in map(int,sys.stdin):
        if(query>primes[-1]):
            for i in range(primes[-1]+1,query+1):
                if isPrime(i):
                    primes.append(i);
        print(len([x for x in primes if x<=query]))
solve()

Python: import math

a = [1]*1000000
for i in range(2,1000000):
    for j in range(i+i,1000000)[::i]:
        a[j] = 0

b = [0]*1000000
b[0] = b[1] = 0
for i in range(2,1000000):
    if a[i] == 1:
        b[i] = b[i-1] + 1
    else:
        b[i] = b[i-1]

while True:
    try:
        print(b[int(input())])
    except EOFError:
        break

Python: import sys
pr = [1]*1000000
pr[0] = 0
pr[1] = 0
for i in range(2,int(len(pr)/2)+1):
	if pr[i]==1:
		j = i*2
		while j < int(len(pr)/2)+1:
			pr[j] = 0
			j += i

for line in sys.stdin:
	n = int(line)
	cnt = 0
	for i in range(n+1):
		if pr[i]==1:
			cnt += 1
	print(cnt)

Python: import sys

input_list = list(int(i) for i in sys.stdin)
max_n = min(1000000, max(input_list) + 1)

prime_list = list(i % 2 for i in range(max_n))
prime_list[1], prime_list[2] = 0, 1
i = 3
while i * i < max_n:
    if prime_list[i]:
        for j in range(i * 2, max_n, i):
            prime_list[j] = 0
    i += 2

for i in range(1, max_n):
    prime_list[i] += prime_list[i - 1]

inset = sorted((n, i) for i, n in enumerate(input_list))
outset = sorted((t[1], prime_list[t[0]]) for t in inset)
for t in outset:
    print(t[1])

Python: while True:
    try:
        n = int(input())
        nums = list(range(n + 1))
        nums[1] = 0
        for i in range(n):
            if nums[i] > n ** 0.5:
                break
            if nums[i] == 0:
                continue
            for j in range(nums[i] * 2, n + 1, nums[i]):
                nums[j] = 0
        print(n + 1 - nums.count(0))
    except:
        break