Go: package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		flag := false
		count := 0

		for i := 3; i <= num; i += 2 { //1を除く入力値以下の数字
			for j := 3; j < i; j += 2 {
				if i%j == 0 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count + 1)
	}
}

Python: import sys
def prime(n):
  i = 2
  if n == 1:
    l = []
  else:
    l = [2]
  while i < n:
    i += 1
    for j in l:
      if i % j == 0:
        break
    else:
      l.append(i)
  return len(l)
for line in sys.stdin.readlines():
  n = int(line)
  print(prime(n))

Python: import sys
s=[2]
for i in range(3,999999):
	for j in range(2,i-1):
		if not i%j:break
	else:
		s.append(i)
		# print(i)
for n in sys.stdin:
	n=int(n)
	cnt=0
	for i,iv in enumerate(s):
		if iv>n:
			print(i)
			break
	else:
		print(i+1)

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

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

Python: import numpy
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break
def primesfrom3to(n):
    sieve = numpy.ones(int(n/2), dtype=numpy.bool)
    for i in range(3,int(n**0.5)+1,2):
        if sieve[int(i/2)]:
            sieve[int(i*i/2)::int(i)] = False
    return 2*numpy.nonzero(sieve)[0][1::]+1
if __name__ == "__main__":
    array = list(get_input())
    for i in range(int(len(array))):
        primeList = list(primesfrom3to(int(array[i])))
        primeList.insert(0,2)
        #print(primeList)
        print(len(primeList))

Python: DP = [0,1,2]

while True:
    try:
        n = int(input())
        if len(DP) < n:
            for i in range(len(DP) + 1,n+1):
                YN = 0
                for j in range(2,i - 1):
                    if i % j == 0:
                        DP.append(DP[len(DP) - 1])
                        YN = 1
                        break
                    elif j ** 2 > i:
                        DP.append(DP[len(DP) - 1] + 1)
                        break

        print(DP[n - 1])
    except EOFError:
        break

Python: LIMIT = 10000000

isPrime = [True for _ in range(LIMIT)]

isPrime[0] = isPrime[1] = False

for i in range(2, int(LIMIT ** 0.5)+1):
  if isPrime[i]:
    for j in range(2 * i, LIMIT, i):
      isPrime[j] = False

countPrime = [0 for _ in range(LIMIT)]

for i in range(1, LIMIT):
  countPrime[i] = countPrime[i-1] + isPrime[i]

try:
  while True:
    n = int(input())
    print(countPrime[n])
except EOFError:
  pass

Python: kazu=[]
Max=1000000
def era(kazu,Max):
    sosu=list(range(2,Max))
    while True:
        num=sosu[0]
        if num>=Max**0.5:
            kazu+=sosu
            return kazu
        kazu.append(num)
        sosu=[i for i in sosu if i%num!=0]
era(kazu,Max)
while True:
    try:
        n=int(input())
        if n==1:
            print(0)
        elif n==2:
            print(1)
        elif n>=max(kazu):
            print(len(kazu))
        else:
            for i in range(n+1):
                if kazu[i]==n:
                    print(i+1)
                    break
                elif kazu[i]>n:
                    print(i)
                    break
    except EOFError:
        break

Python: # 準備
num_list = [0] * 1000000
i = 2
cnt = 0
for num in range(2,len(num_list)):
    if num_list[i] == -1:
        num_list[i] = num_list[i-1]
        i += 1
        continue
    cnt+=1
    num_list[i] = cnt
    # num_list[i*2::i] = -1
    for j in range(i*2,len(num_list),i):
        num_list[j] = -1
    i += 1

while True:
    try:
        n = int(input())
    except Exception as e:
        break
    print(int(num_list[n]))

Python: import math
import sys

def get_primes(n):
    search = list(range(2, n+1))
    primes = []
    while True:
        primes.append(search[0])
        for i,x in enumerate(search):
            if x % primes[-1] == 0:
                del search[i]
        if len(search) == 0:
            return primes
        if search[0] >= math.sqrt(n):
            primes.extend(search)
            return primes

for line in sys.stdin.readlines():
    n = int(line)
    if n < 2:
        print(0)
    else:
        print(len(get_primes(n)))

Python: # returns the number of prime numbers less than or equal to n
def sieve(n):
    prime = [True] * (n+1)
    prime[0] = prime[1] = False
    count = 0
    for i in range(2, n+1):
        if prime[i]:
            count += 1
            for j in range(2*i, n+1, i):
                prime[j] = False
    return count


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

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

import sys
import math

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

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, 2):
        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())
        if num == 1:
            cnt = 0
        else:
            cnt = 0
            for i in range(3, num + 1, 2):
                if is_prime(i):
                    cnt += 1
            cnt += 1

        print(cnt)

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

Python: def prime(n, p):
  cnt = 0
  for i in range(n+1):
    if(p[i]):
      cnt += 1
  return cnt
  
p = [True for i in range(1000001)]
p[0] = False
p[1] = False
for i in range(2, 500001):
  for j in range(2, 1000000//i + 1):
    p[i * j] = False

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

Python: #coding:utf-8
import time
import math
import numpy as np

def flatten(L):
    if isinstance(L, list):
        if L == []:
            return []
        else:
            return flatten(L[0]) + flatten(L[1:])
    else:
        return [L]

def Eratos(data):

    p_list = [] # ????????????
    tmp = []
    num = int(math.sqrt(len(data)))+1
    for i in data:
        i=data[0]
        if i>num:
            break
        else:
            p_list.append(i)
            for j in data:
                if j%i == 0:
                    data.remove(j)
        
    p_list.append(data)
    return p_list

x = int(input())

r_list = list(range(2,(x+1)))
ans = []
ans = Eratos(r_list)

print(len(flatten(ans)))

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

Python: def prime_count(N):
    primes = [2, 3]
    count = 1
    for n in range(5, N+1, 2):
        isprime = True
        for i in range(1, len(primes)):
            if primes[i] ** 2 > n:
                break
            if n % primes[i] == 0:
                isprime = False
                break
        if isprime:
            count += 1
    return count

while True:
    try:
        print(prime_count(int(input())))
    except:
        break

Python: import sys
from math import sqrt

for line in sys.stdin:
    n = int(line.strip())
    L, pn, tmp = int(sqrt(n)), [], [i for i in range(2, n+1)]
    while tmp[0] < L+1:
        v = tmp.pop(0)
        pn.append(v)
        tmp = list(filter(lambda x: x%v!=0, tmp))
    for t in tmp: pn.append(t)
    print(len(pn))