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: #!/usr/bin/env python3
import itertools
import math
import sys

MAX = 999999


def sieve_of_eratosthenes(max):
    is_prime = [True] * (max + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(math.sqrt(max)) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * i, max + 1, i):
            is_prime[j] = False
    return filter(lambda x: is_prime[x], range(max + 1))


def main():
    p = list(sieve_of_eratosthenes(MAX))
    for l in sys.stdin:
        n = int(l)
        print(len(list(itertools.takewhile(lambda x: x <= n, p))))


if __name__ == '__main__':
    main()

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

LIMIT = 1000000
is_prime = [True] * (LIMIT+1)
p = 2
while p**2 <= LIMIT:
    if is_prime[p]:
        for i in range(p*2, n+1, p):
            is_prime[i] = False
    p += 1

for line in sys.stdin.readlines():
    n = int(line.strip())
    if n <= 1:
        print(0)
        continue
    if n == 2:
        print(1)
        continue
    num_prime = 1
    for i in range(3, n+1):
        if is_prime[i]:
            num_prime += 1
    print(num_prime)

Python: # -*-coding:utf-8
#n??\???????´???°?????°

import fileinput
import math

def main():

    for line in fileinput.input():
        tokens = list(map(int, line.strip().split()))

        primeNumber = tokens[0]
        ans = 1
        for i in range(3, primeNumber+1, 2):
            flag = 0
            for j in range(3, int(math.sqrt(i))+1, 2):
                if(i%j == 0):
                    flag = 1
                    break

            if(flag == 0):
                ans += 1

        print(ans)

if __name__ == '__main__':
    main()

Python: import math
b=[]
b.append(1)
b.append(2)
count=1
s=0
while s<30:
    try:
        x=int(input())
        if x>b[count]:
            for i in range(b[count]+1,x+1):
                count1=0
                
                for j in range(2,int(math.sqrt(i))+1):
                    if i%j==0:
                        count1=1
                        break
                if count1==0:
                    count+=1
                    b.append(i)
            print(count)
        else:
            for i in range(count+1):
                if b[i]>x:
                    print(i-1)
                    break
                elif b[i]==x:
                    print(i)
                    break
        s+=1
    except EOFError:
        break

Python: import sys
import math

lines = str(sys.stdin.read()).strip().split("\n")

for line in lines:
    line = int(line)
    pList = []
    sList = list(reversed(list(range(3, line + 1))[::2]))
    while sList[-1] < (int(math.ceil(math.sqrt(line))) + 1):
        pList.append(sList.pop())
        for p in pList:
            sList = list(filter(lambda i: i % p != 0, sList))
    pList.extend(sList)
    pList.append(2)
    print(len(pList))

Python: from math import sqrt
cash = {}
def isprime(n):
    if n in cash:
        return cash[n]
    if n == 1:
        cash[n] = 0
        return 0
    if n == 2:
        cash[n] = 1
        return 1
    if n % 2 == 0:
        cash[n] = 0
        return 0
    for i in range(2,int(sqrt(n)+1)):
        if n % i == 0:
            cash[n] = 0
            return 0
    cash[n] = 1
    return 1

from sys import stdin
cash2 = {}
for i in stdin:
    i = int(i)

    c = sum(isprime(n) for n in range(2,i+1))
    print(c)

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

import sys

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)
    
    for i in range(3, no // 2):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

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)

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

import sys
import os
import math



def Eratosthenes(n):
    lst = [i for i in range(2, n+1)]
    primes = []
    sqrt_n = n ** 0.5

    while True:
        first = lst.pop(0)
        if first < sqrt_n:
            primes.append(first)
            new_lst = []
            for v in lst:
                if v % first != 0:
                    new_lst.append(v)
            lst = new_lst
        else:
            # ??????
            return primes + [first] + lst

if __name__ == '__main__':
    inputs = sys.stdin.readlines()
    for s in inputs:
        n = int(s)
        lst = Eratosthenes(n)
        print(len(lst))

Python: def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break
if __name__ == '__main__':
    array = list(get_input())
    cnt,flag = 0,0
    for i in range(len(array)):#?????°????????°????????????
        for j in range(2,int(array[i])+1):#1??????????´??????¢??????????´???°??¢?´¢????????????
            flag = 0
            if j == 2:
                flag = 1
            for k in range(2,j):
                if j % k == 0:
                    flag = 0
                    break
                flag = 1
            if flag == 1:
                cnt += 1  
        print(cnt)
        cnt = 0

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

while True:
    try:
        n = int(input()) + 1
        print(sum([1 for i in range(n) if primes[i]]))
    except:
        break

Python: # coding: utf-8


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:
            # print([i for i, b in enumerate(input_list) if b == True])
            return sum(input_list)

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


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

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