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: while True:
    try:
        n=int(input())
        num=list(range(n+1))
        num[1]=0
        for i in range(n):
            if num[i]>n**0.5:
                break
            if num[i]==0:
                continue
            for j in range(num[i]*2,n+1,num[i]):
                num[j]=0
        print(n+1-num.count(0))
    except:
        break

Python: # coding: utf-8
# Your code here!

a=[1 for i in range(1000001)]
b=[0,0]
a[0]=a[1]=0
c=0
for i in range(2,1000001):
    if a[i]==1:
        c+=1
        for j in range(i*2,1000001,i):
            a[j]=0
    b.append(c)

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

Python: #init
max_num = 1000000
is_prime_num = [True for i in range (max_num+1)]

#0, 1 --- not prime number
is_prime_num[0] = False
is_prime_num[1] = False
end = int(max_num ** .5)

for i in range(2, end+1):
    if is_prime_num[i]:
        for j in range(i*i, max_num+1, i):
            is_prime_num[j] = False


while True:
    try:
        n = int(input())
        prime_cnt = 0
        for i in range(1, n+1):
            if is_prime_num[i]:
                prime_cnt = prime_cnt + 1
                   
   
        print(str(prime_cnt))
    except:
        break

Python: import sys

prime = [2,3,5,7,11,13,19,23,29,31]

shieve1 = [1]*1001
for i in prime:
    itr = i-1
    while(itr<1000):
        shieve1[itr] = 0
        itr += i

for i in range(32,1000):
    if shieve1[i]:
        prime.append(i+1)

shieve2 = [1]*(10**6+1)

for i in prime:
    itr = i-1
    while(itr<10**6):
        shieve2[itr] = 0
        itr += i

for i in range(1001,10**6+1):
    if shieve2[i]:
        prime.append(i+1)

for line in sys.stdin:
    n = int(line)
    cont = 0
    for i in prime:
        if i<=n:
            cont += 1
        else:
            break
    print(cont)

Python: # Aizu Problem 0009: Prime Number
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(10**6)

for line in sys.stdin:
    n = int(line)
    idx = bisect.bisect_right(primes, n)
    print(idx)

Python: import sys
import math
pr = [1]*1000000
pr[0] = 0
pr[1] = 0
maxval = math.ceil(math.sqrt(999999))
for i in range(2,maxval):
	if pr[i]==1:
		j = i*2
		while j < maxval:
			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 math
import sys

def prime_calc(n):
    rootN = math.floor(math.sqrt(n))
    prime = [2]
    data = [i + 1 for i in range(2,n,2)]
    while True:
        p = data[0]
        if rootN <= p:
            return len(prime + data)
        prime.append(p)
        data = [e for e in data if e % p != 0]

def main():
    l = []

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

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

if __name__ == "__main__":
    main()

Python: import sys

MAX = 999999
L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]

def is_prime(n):
  if n == 2:return True
  if n % 2 == 0:return False
  for i in range(3,int(n**0.5)+1,2):
    if n % i == 0:return False
  return True

def is_prime_2(n):
  a = int(n ** 0.5)
  for i in L:
    if i > a:return True
    if n % i == 0:return False
  return True

def prime_count(n):
  result = 0
  if n >= 2:result+=1
  for i in range(3,n+1,2):
    if is_prime_2(i):result+=1
  return result

def prime_list(n):
  result = []
  if n >= 2:result.append(2)
  for i in range(3,n+1,2):
    if is_prime(i):result.append(i)
  return result

L2 = prime_list(MAX)

def prime_count_2(n):
  for i,v in enumerate(L2):
    if n > v:return i
  return len(L2)

for n in sys.stdin:
  print(prime_count_2(int(n)))

Python: 
prime=[False]*1000000
for i in range(2,1001):
    for j in range(i*2,1000000,i):
        prime[j]=True

while True:
    try:
        n=int(input())
    except:
        break
    print(prime[2:n+1].count(False))

Python: import sys

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

for e in sys.stdin:
    n = int(e)
    print(len(primes(n)))

Python: import math

def Eratos(n):
	primes = [2]
	if n % 2 == 0:
		num = [2*i+1 for i in range(1,n/2)]
	else:
		num = [2*i+1 for i in range(1,(n+1)/2)]
	tmp = []

	top = 1
	while top < math.sqrt(n):
		top = num[0]
		for i in range(1,len(num)):
			if num[i] % top != 0:
				tmp.append(num[i])
		num = tmp
		tmp = []
		primes.append(top)
	for i in range(len(num)):
		primes.append(num[i])
	return primes

def list_count(list_a,n):
	cont = 0
	for i in range(len(list_a)):
		if list_a[i] > n:
			break
		else:
			cont += 1
	return cont

primes = Eratos(1000000)
while True:
	try:
		n = int(input())
		print(list_count(primes,n))
	except EOFError:
		break

Python: from math import sqrt
I_list=[]
prime_list=[]
while True:
    try:
        I_list.append(int(input()))
    except:
        break
I_max=max(I_list)
search_set={x for x in range(2,I_max+1)}
 
 
p=-1
while p<=sqrt(I_max):
    p=min(search_set)
    prime_list.append(p)
    search_set={x for x in search_set if x%p !=0 }
 
search_list=sorted(list(search_set))
prime_list+=search_list
 
#print(prime_list)
 
 
for i in I_list:
    lower_set={j for j in prime_list if j<=i } 
#   print(lower_set)
    print(len(lower_set))