Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <iostream>
using namespace std;

#define MAX_N 2000000
int prime[MAX_N];



int main(){
	prime[1] = 1;
	prime[2] = 0;
	prime[3] = 0;
	for(int i = 2; i<=MAX_N;i++){
		if(prime[i] == 0)
			for(int j=2*i;j<=MAX_N;j=j+i)
				prime[j] = 1;
	}
	
	int n;
	int num=0;
	while(cin.eof()==0){
		cin >> n;	
		for(int k = 1;k<=n; k++){
			if(prime[k]==0)
				num++;
		}
		cout << num << endl;
		num = 0;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) { prime[length] = p; length++; return; }
int main(){
	insert(2);
	for (ll i = 3; i < 1000000; i += 2) {
		for (ll j = 0; j < length; j++)
			if (i%prime[j] == 0)goto cont;
			else if (prime[j] > sqrt(i))break;
		insert(i);
	cont:;
	}
	ll n; while (cin >> n) {
		ll ans = 0;
		while (prime[ans] <= n&&ans < length) {
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() 
{
  int a=999999;
  bool list[a+1];
  memset(list,true,sizeof(list));
  list[1]=false;
  for(int i=4;i<=a;i=i+2)
  {
    list[i]=false;
  }
  for(int i=3;i*i<=a;i=i+2)
  {
    if(list[i]==true)
    {
      for(int k=i*i;k<=a;k=k+i+i)
      {
        list[k]=false;
      }
    }
  }
  int temp;
  while(scanf("%d",&temp))
  {
    int count=0;
    for(int i=1;i<=temp;i++)
    {
      if(list[i]==true)
      {
        count++;
      }
    }
    printf("%d\n",count);
  }
  
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i<= MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long n,i,s;
	while(cin>>n)
	{
		s=0;
		for(i=2;i<=n;i++)
		{
			if(i==2||i==3||i==5||i==7)s++;
			else if(i%2!=0&&i%3!=0&&i%5!=0&&i%7!=0)s++;
		}
		cout<<s<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int isPrime[1000001];
int main(){

  fill(isPrime,isPrime+1000001,1);
  isPrime[0]=isPrime[1]=0;
  for(int i = 2 ; i*i < 1000001 ; i++ ){
    if(isPrime[i])for(int j=i*2 ; j < 1000001 ; j+=i)isPrime[j]=0;
  }
  int n;
  while(cin >> n){
    int cnt = 0;
    for(int i = 2 ; i <= n ; i++ ){
      if(isPrime[i])cnt++;
    }
    cout << cnt << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
int cnt,n,prime[10000007];
using namespace std;

void getprime()
{
	/*int tt=0,flag;
	prime[tt++]=2;
	for(int i=3;i<=1000000;i++) 
	{
		flag=1;
		for(int j=0;prime[j]*prime[j]<=i;j++)
		{
			if(i%prime[j]==0)
			{	
			    flag=0;
		     	break;
			}
		}
		if(flag==1) prime[tt++]=i;
	}*/
	memset(prime,0,sizeof(prime));  
    for(int i = 2; i<=10000007; i++)  
    {  
        if (!prime[i]) prime[++prime[0]] = i;  
        for(int j = 1;j<=prime[0] &&prime[j] < 10000007/i;j++ )  
        {  
            prime[prime[j]*i] = 1;  
            if(i%prime[j]==0) break;  
        }  
    } 
}

int main()
{	getprime();
	while(cin >> n)
	{
       for(int i=1;;i++)
	   {
       	if(prime[i]>n)
		   {
       		printf("%d\n",i-1);
       		break; 
		   }
	   }
    }
}

C++: #include <iostream> 
#include <math.h>
using namespace std; 

int main(void) { 
	int A[1000000];
	for(int i = 0; i < 1000000; i++){
		A[i] = 1;
	}
	A[0] = A[1] = 0;
	for(int i = 2; i < sqrt(1000000); i++){
	    if(A[i] == 1){
    		for(int j = 2; i * j < 1000000; j++){
                	A[i * j] = 0;
		    }
	    }
	}
	int n;
	while(cin >> n){ 
		int COUNT = 0;
		for(int i = 1; i <= n; i++){
            COUNT += A[i];
		}
		cout << COUNT << endl;
	}
	return 0; 
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[80000];
    int n;
    a[0]=2;
    int k=1;
while(cin>>n){
    for(int i=3;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<k<<endl;
    k=1;
 }
}

C++: #include<stdio.h>
int main ()
{
    int n,i,m,sum;
    while(1)
    {
        sum=0;
        scanf("%d",&n);
        for(m=2;m<=n;m++)
        {
            for(i=2;i<=m;i++)
            {
                if(m%i==0 && i<m)
                {
                    break;
                }
                if(i==m)
                {
                    sum=sum+1;
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

C++: 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)
    if n%2 != 0:
        sieve = numpy.append(sieve,n/2)
    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))

C++: #include <iostream>

using namespace std;

int vtoad(int);

int main(void){
	char	*val;
	int	c,N,ad;

	while(cin >> N){
		c=2;
		val = new char[N/3+2];
		for(int i=0;i<N/3+2;i++)
			val[i]=0;

		for(int i=1;i*6-1<=N;i++)
			for(int j=-1;j<=1;j+=2)
				if(i*6+j<=N&&(ad=vtoad(i*6+j)))
					if(!val[ad]){
						c++;
						for(int k=2;(i*6+j)*k<=N;k++)
							if(ad=vtoad((i*6+j)*k))
								val[ad]=1;
				}
		cout << c << endl;

		delete [] val;
	}

	return 0;
}

int vtoad(int val){
	if(!((val+1)%6))
		return (val+1)/3-1;
	else if(!((val-1)%6))
		return (val-1)/3+2;
	else
		return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

vector<int>soe(int n);

int main(void)
{
	int num;
	while(cin >> num){
		vector<int>sosu(num);
		sosu = soe(num);
		int a_size = sosu.size();
		cout << a_size << endl;
		/*for(int i = 1; i < num; i++){
			cout << sosu[i] <<endl;
		}*/
	}	
	return 0;
}

vector<int>soe(int n){
	vector<int>hyo(n);
	for(int i = 2; i < n; i++){ //??\???
		hyo[i] = i;
	}
	for(int i = 2; i*i < n; i++){ //???????????§??°?????????
		if(hyo[i])
		for(int j = i*i; j < n; j += i){
			hyo.erase(remove(hyo.begin(), hyo.end(), j), hyo.end());
		}
	}
	hyo.erase(remove(hyo.begin(), hyo.end(), 0), hyo.end());
	hyo.erase(remove(hyo.begin(), hyo.end(), 1), hyo.end());
	return hyo;
}