Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

Python: import sys

def prime(maximum):
    sieve = [True] * (maximum + 1)

    def sieved(prime):
        for not_prime in range(prime + prime, len(sieve), prime):
            sieve[not_prime] = False

    sieve[0] = sieve[1] = False
    sieved(2)
    for x in range(3, int(maximum ** 0.5) + 1, 2):
        if sieve[x]: sieved(x)
    return [prime for prime, is_prime in enumerate(sieve) if is_prime]

count = 0
numbers = []
for line in sys.stdin:
    numbers.append(int(line))
    count += 1

counts = []
for i in range(count):
    counts.append(0)

for prime in prime(1000000):
    if prime > 999999:
        break
    for i in range(count):
        if prime <= numbers[i]:
            counts[i] += 1

for count in counts:
    print(count)

Python: def solve(n):
	A=[0 for i in range(n+1)]
	A[2]=1
	for i in range(2,n+1):
		cnt=0
		for j in range(1,i+1,2):
			if i%j==0:
				cnt+=1
		if cnt==2:#1??¨????????°??????
			A[i]=1
	return sum(A) 

while True:
	try:
		n = int(input())
		print(solve(n))
	except EOFError:
		break

Python: LIMIT = 999999

prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]

for i in range(3, LIMIT + 1):
    if prime[i - 1]:
        for j in range(i ** 2, len(prime), i):
            prime[j - 1] = 0

while True:
    try:
        n = int(input())
    except EOFError:
        break
    
    print(n, sum(prime[:n]))

Python: def mk_table(n):
    res = [1] * (n + 1)
    res[:2] = [0, 0]

    for i in range(2, n):
        if i ** 2 > n:
            break

        if res[i] == 1:
            j = 2
            while i * j <= n:
                res[i * j] = 0
                j += 1

    return res


tbl = mk_table(999999)
try:
    while 1:
        print(len([x for x in tbl[:int(input())+1] if x == 1]))
except Exception:
    pass

Python: MAX = 1000000
SQRT = 1000     # sqrt(MAX)
 
prime = [0] * MAX
 
def sieve():
    for i in range(3, MAX, 2):
        prime[i] = 1
    for i in range(3, SQRT, 2):
        if prime[i] == 1:
            for j in range(i*i, MAX, i):
                prime[j] = 0
 
sieve()
cnt = [0] * (MAX+1)
cnt[2] = f = 1
for i in range(3, MAX, 2):
    if prime[i]:
        f += 1;
    cnt[i] = cnt[i+1] = f
     
while True:
    try:
        print(cnt[int(input())])
    except EOFError:
        break

Python: def is_prime(x):
    x=abs(x)
    if x==2:
        return True
    if x<2 or x&1==0:
        return False
    return pow(2,x-1,x)==1
while True:
    try:
        n=int(input())
    except:
        break
    print(sum(is_prime(i)==True for i in range(2,n+1)))

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

def sieve(n):
    p = 0
    primes = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if(is_prime[i]):
            primes.append(i)
            p += 1
            for j in range(i*2,n,i):#iごとに増える
                is_prime[j] = False
    return p

if(__name__ == "__main__"):
    while(True):
        try:
            n = int(input())
        except:
            break
        print(sieve(n) + "\n")

Python: import sys
def main():
    for line in sys.stdin:
        n = int(line)
        hoge = [i for i in range(2, n + 1) if i % 2 != 0 or i == 2]
        fuga = [2]
        for i in range(1, len(hoge)):
            cnt = 0
            for j in range(i):
                if hoge[i] % hoge[j] != 0:
                    cnt += 1
            if cnt == i:
                fuga.append(hoge[i])
        print(len(fuga))


if __name__ == "__main__":
    main()

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

Python: while True:
    try:
        M = int(input())
    except EOFError:
        break
    N = (M+1)//2-1
    temp = [i for i in range(1, N+1)]
    for j in range(1,(N-1)//3+1):
        for i in range(1,j+1):
            if i+j+2*i*j>N:
                break
            try:
                temp.remove(i+j+2*i*j)
            except ValueError:
                pass
    print(len(temp)+1)

Python: import math
def pri(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return True

l=[i for i in range(110000)if pri(i) ]

while True:
    n = int(input())
    if n == 0: break
    print(sum(l[:n]))

Python: import math

def main():
    while True:
        try:
            n = int(input())
            count = 0
            for x in range(2,n+1):
                flag = 0
                for i in range(2,x):
                    if x%i == 0:
                        flag = 1
                        break
                if flag == 0:
                    count += 1
            print(count)      
        except EOFError:
            exit()
      

if __name__ == '__main__':
    main()

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

import sys
import math

prim_no = {2: True}                    # ????????°????´???°??§??????????????????????????????

def is_prime(no):
    if no == 2 or no == 1:
        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, 2):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

def main():
    prim_vals = {}                         # ????????°?????§????´???°????????°
    while True:
        num = sys.stdin.readline()
        if num is None or num.strip() == '':
            break

        num = int(num.strip())
        if prim_vals.get(num) is not None:
            cnt = prim_vals.get(num)
        else:
            if num == 1:
                cnt = 0
            else:
                cnt = 0

                if num % 2 == 0:
                    start_num = num -1
                else:
                    start_num = num
                    
                for i in range(start_num, 0, -2):
                    if prim_vals.get(i) is not None:
                        cnt += prim_vals.get(i)
                        break
                    
                    if is_prime(i):
                        cnt += 1
                        
                prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????

        print(cnt)

if __name__ == '__main__':
    main()
    #print(prim_no)

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,random

rand = random.randint

def prime(n):
	if n == 2:
		return True
	if n < 2 or n & 1 == 0:
		return False
	d = (n-1) >> 1
	while d & 1 == 0:
		d >>= 1
	
	for i in range(10):
		a = rand(1,n-1)
		t = d
		y = pow(a,t,n)
		while t != n-1 and y != 1 and y != n-1:
			y = pow(y,2,n)
			t <<= 1
		if y != n-1 and t & 1 == 0:
			return False
	return True

a = [prime(i) for i in range(1000000)]

for s in sys.stdin:
	i = int(s)
	print(a[:i+1].count(True))