Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

Python: import sys
results = {}
def fact(n):
    if n in results:
        return results[n]
    ret = [1]
    if n%2==0:
        ret.append(2)
        results[n]=ret
        return ret
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:
            ret.append(i)
            results[n]=ret
            return ret
    results[n]=ret
    return ret
prime_results = {}
def isPrime(n):
    if n in prime_results:
        return prime_results[n]
    if n<=1:
        prime_results[n]=False
        return False
    if n==2:
        prime_results[n]=True
        return True
    if fact(n)==[1]:
        prime_results[n]=True
        return True
    else:
        prime_results[n]=False
        return False
lines = sys.stdin.readlines()
answers = {}
for line in lines:
    inp = int(line)
    if inp in answers:
        print(answers[inp])
        continue
    s=0
    for i in range(2,inp+1):
        if isPrime(i):
            s+=1
        answers[i]=s
    print (s)

Python: def Eratosthenes(n):
	N = [1 for i in range(0,n+1)]
	i = 3
	while i*i<=n:
		if N[i]:
			j = i*3
			while j<=n:
				N[j] = 0
				j += i*2
		i += 2
	return N

while True:
	N = Eratosthenes(999999)
	try:
		n = int(input())
	except EOFError:
		break
	cnt = 0
	if n>=2:
		cnt = 1
	for i in range(3, n+1, 2):
		cnt += N[i]
	print(cnt)

Python: import sys
from math import sqrt
from itertools import takewhile
prime = [2]
n_list = list(map(lambda x:int(x.rstrip("\n")),sys.stdin.readlines()))
for n in n_list:
    if prime[-1] < n:
        for x in range(prime[-1]+1,n+1):
            if all(map(lambda p:x % p != 0,filter(lambda z:sqrt(x) >= z,prime))):
                prime.append(x)

    print(len(list(takewhile(lambda x:x <= n, prime))))

Python: import math
import sys
isPrime=[False, False]
for i in range(2,1000000):
    isPrime.append(True)
for i in range(2,int(math.sqrt(1000000))):
    if isPrime[i]:
        for j in range(i*i, 1000000, i):
            isPrime[j]=False
nPrime=[]
cnt=0
for i in range(0,1000000):
    if isPrime[i]:
        cnt=cnt+1
    nPrime.append(cnt)
for l in sys.stdin:
    print(nPrime[int(l)])

Python: def cntPrime(n):
    mx = sqrt(n) + 1
    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, floor(n/c) + 1, 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: import sys
import math

def isPrime(n):
    if n < 2:
        return 0
    elif n == 2:
        return 1
    elif n%2 == 0:
        return 0   
    num = int(math.sqrt(n))
    for i in range(3, num+1, 2):
        if n%i == 0:
            return 0
    return 1;

while True:
    try: 
        n = int(input())
        cnt = 0
        for i in range(2, n+1):
            cnt += isPrime(i)
        print(cnt)
    
    except EOFError:
        sys.exit()

Python: import sys
def isPrime(i):
    if i<2:
        return False
    else:
        for j in range(2,i):
            if j*j>n:
                break
            elif i%j==0:
                return False
        return True

def countPrime(i):
    cnt=0
    for x in range(2,i+1):
        if isPrime(x) == True:
            print(x)
            cnt+=1
    return cnt

while True:
    try:
        n=int(input())
        cnt=0
        for x in range(2,n+1):
            if isPrime(x)==True:
                cnt+=1
        print(cnt)
    except:
        break

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