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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

Python: import sys
import math
from bisect import bisect_right
n = 1000000
a = set(range(3, n, 2))
diff = a.difference_update
for i in range(3, int(math.sqrt(n)), 2):
    if i in a:
        diff(range(i*2, n+1, i))

primes = [2] + list(a)
for l in map(int, sys.stdin.readlines()):
    print(bisect_right(primes, l))

Python: from math import sqrt
from sys import stdin

def pm(n):
    l = list(range(3,n+1)[0::2])
    p = 3
    i = 0
    p = l[i]
    m = sqrt(n)+1
    while p <= m:
        l = l[:i+1] + [n for n in l[i+1:] if n%p != 0]
        i += 1
        p = l[i]
    return len(l) + 1

for n in stdin:
    print (pm(int(n)))

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 <= 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: #!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import sys

def atkin(limit):
    sqrt_limit = int(math.sqrt(limit))
    is_prime = [False] * (limit + 1)
    primes = []
    if limit == 1:
        return primes
    if limit >= 2:
        is_prime[2] = True
    if limit >= 3:
        is_prime[3] = True
    for x in range(1, sqrt_limit):
        for y in range(1, sqrt_limit):
            k = 4*x**2 + y**2
            if k <= limit and (k%12 == 1 or k%12 == 5):
                is_prime[k] ^= True
            k = 3*x**2 + y**2
            if k <= limit and k%12 == 7:
                is_prime[k] ^= True
            k = 3*x**2 - y**2
            if x > y and k <= limit and k%12 == 11:
                is_prime[k] ^= True

    r = 5
    while r**2 < limit:
        if is_prime[r]:
            i = r**2
            while i < limit:
                is_prime[i] = False
                i += r**2
        r += 1

    for i in range(limit + 1):
        if is_prime[i]:
            primes.append(i)

    return primes

for line in sys.stdin.readlines():
    n = int(line.strip())
    primes = atkin(n)
    #print(primes)
    print(len(primes))

Python: from math import *

search_list = []
prime_list = []
target = 0

def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break
if __name__ == '__main__':
    array = list(get_input())
    for i in range(len(array)):
        #??\????????¨?????????????????????????????§?´???°????????°?????¢?´¢??????
        for j in range(2,int(array[i])+1):
            #??¢?´¢??????????????????
            search_list.append(j)
        #print(sqrt(int(array[i])))
        while True:
            if target > sqrt(int(array[i])):
                prime_list = prime_list + search_list
                break
            prime_list.append(search_list[0])
            target = search_list[0]
            search_list.pop(0)
            k = 1
            while target*k<=search_list[-1]:
                #print(target * k)
                if target*k in search_list:
                    search_list.remove(target*k)
                k += 1
            #print(search_list)
        #print(str(array[i]) + "??\???????´???°???" + str(prime_list) + "??????????????°???" + str(len(prime_list)))
        print(len(prime_list))
        target = 0
        prime_list.clear()
        search_list.clear()

Python: def check_prime(goal):
    true_or_false=False
    for i in range(2,goal):
        if goal%i==0:
             true_or_false=True
    if true_or_false==False:
        return True
    else:
        return False

anss=[]
while True:
    try:
        num=int(input())
        num_of_prime=0
        for i in range(2,num+1):
           if check_prime(i):
               num_of_prime+=1
        anss.append(num_of_prime)
    except:
        break

for ans in anss:
    print(ans)

Python: import math
import sys

def prime_calc(n):
    if n < 2:
        return False
    elif n==2 or n==3 or n==5 or n==7:
        return True
    else:
        rootN = math.floor(math.sqrt(n))
        i = 11
        while rootN > i:
            if n % i == 0:
                return False
            else:
                i += 2

    return True

def prime(n):
    cnt = 0
    for i in range(2, n+1):
        ans = prime_calc(i)
        if ans is True:
            cnt = cnt + 1

    return cnt

def main():
    l = []

    for line in sys.stdin:
        l.append(int(line))

    for line in l:
        print(prime(line))

if __name__ == "__main__":
    main()

Python: import math


def sieve_of_erastosthenes(num):
    if 2 >= num:
        return 1
        
    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

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


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

        input_list = sieve_of_erastosthenes(n)

        print(sum(input_list))

Python: def pm(n):
    l = list(range(3,n+1)[0::2])
    p = 3
    i = 0
    p = l[i]
    m = sqrt(n)+1
    while p <= m:
        l = l[:i+1] + [n for n in l[i+1:] if n%p != 0]
        i += 1
        p = l[i]
    return len(l) + 1

from sys import stdin
for i in stdin:
    print(pm(int(i)))

Python: prime=[2]
for i in range(3,1000000,2):
    primeq=True
    for p in prime:
        if i%p==0:
            primeq=False
            break
        if i<p*p:break
    if primeq:prime.append(i)
while True:
    try:
        n=int(input())
        ans=0
        for p in prime:
            if p>n:break
            ans+=1
        print(ans)
    except:break

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

# n??\???????´???°?????°???????????¢??°
def prime(n):
    l = range(0,n+1)
    i,k = 0,2
    result = 1

    if n >= 3:
        prime_nums = [2, 3]
    else:
        prime_nums = []

    while i <= n:
        while l[i] > k:
            result = l[i]%k
            k = k+1
            if result == 0:
                break
            if (l[i]-1 == k) and (result != 0):
                prime_nums.append(l[i])

        i, k = i+1, 2

    #return prime_nums
    return len(prime_nums)

array = []
for i in sys.stdin:
    array.append(int(i))

l = len(array)
for i in array:
    psum = prime(i)
    print(psum)

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