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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]==true){
        for(long long int  = (long long int)i*i;j<MAX;j=j*j){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
    int X,ans,count;
    bool num[1000001]={};
    for(int i=2;i<=1000000;i++){
        if(!num[i]) 
        for(int j=i*2;j<=1000000;j+=i)  num[i] = true;
    }
    while(cin >> X)
    {
        count = 0;
        for(int i=2;i<=X;i++){
            if(!num[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

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

using namespace std;

vector<bool> prime(1000010, 1);

signed main(){
    prime[0] = 0; prime[1] = 0; prime[2] = ( const ) 1;
    int ret = 0;
    int n; scanf( "%d", &n );
    for( int i = 2; i * i <= n; i++ ){
        if( prime[i] ){
            for( int j = 1; ( j + 1 ) * i <= n; j++ ){
                prime[i * ( j + 1 )] = 0;
            }
        }
    }
    for( int i = 0; i <= n; i++ )
    {
        if( prime[i] )
        {
            ret++;
        }
    }
    printf( "%d\n", ret );
    return 0;
}

C++: #include <iostream>
using namespace std;
int n;
#define MAX_N 1000000

int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数

// n以下の素数の数を返す
int sieve(int n) {
    int p = 0;
    for(int i=0;i<=n;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i=2; i<=n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for(int j=2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

main() {
    sieve(MAX_N);
    while(cin>>n) {
        int ans=0;
        for(int i=2;i<=n;i++) {
            if(is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

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

static bool prime[MAX_N];
 static int num[MAX_N] = { 0 };

void ini()
{
	for (int i = 2; i < MAX_N; i++)
		prime[i] = true;
	for (int i = 2; i < MAX_N; i++)
	{
		if (!prime[i])
		{
			num[i] = num[i - 1] + prime[i];
			continue;
		}
		else
		{
			for (int j = i * 2; j < MAX_N; j += i)
			{
				if (prime[j] && j%i == 0)
					prime[j] = false;
			}
		}
		num[i] = num[i - 1] + prime[i];
	}
}

void solve()
{
	int n;
	while (cin >> n)
		cout << num[n] << endl;
}

int main()
{
	ini();
	solve();
	return 0;
}

C++: #include <cstdio>
int d[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i])continue;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	for(i=2;i<=999999;i++) {
		if(!d[i])r++;
		d[i]=r;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",d[n]);
	}
}

C++: #include<iostream>
int main(){
	for(int m,n,p;!(std::cin>>n).eof();){
		if(n<3)
			p=!(n-2);
		else for(m=3,p=1;m<=n;m+=2){
			p++;
			if(m<2)
				p--;
			else{
				for(int i=3;i*i<=m;i+=2)
					if(m%i==0){p--;break;}
			}
		}
		printf("%d\n",p);
	}
}

C++: 
def generate (n)
    $P = Array.new(n, false)
    i = 3
    until i > n
        $P[i] = true
        i += 2
    end
    i = 3
    $P[2] = true
    until i > n
        if ! $P[i]
            i += 2
            next
        end
        j = i + i
        until j > n do
            $P[j] = false
            j += i
        end
        i += 2
    end
end

def is_prime (n)
    return $P[n] ? 1 : 0
end

def solve (n)
    return ->() {
        res = 0
        (n+1).times {|v| res += is_prime(v) }
        res
    }.call
end

generate 1000000 
while s = gets do
    n = s.to_i
    p solve n
end

C++: #include<stdio.h>

int main(void)
{
	int d=2,i,j,s[10000],x;

	while((scanf("%d",d))!=EOF)
	{
		for(i=0;i<=d;i++){
			s[i]=1;}
		x=0;
		if(d<=1){
			printf("%d\n",0);
		}
		else
		{
			for(i=2;i<=d/2;i++)
			{
			  if(s[i]!=0)
			  {
				for(j=i*2;j<d;j+=i)
				    s[j]=0;
			  }
			}
		for(i=0;i<=d;i++)
			x+=s[i];
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include<iostream>
using namespace std;
#define N 1000000
bool p[1000000];
int main(){
  int n;

  for(int i=0;i<N;i++)p[i]=true;
  p[0]=p[1]=false;

  for(int i=0;i<=N/2;i++)
    if(p[i]==true)
      for(int j=i*2;j<N;j+=i)
	p[j]=false;

  while(cin>>n){
    int count=0;
    for(int i=0;i<=n;i++)
      if(p[i]==true)count++;
    cout<<count<<endl;
  }
  return 0;
}

C++: /*
http://blog.csdn.net/liuke19950717
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef int ll;
const int maxn= 999999+5;
ll prime[maxn];
int main()
{
	ll cnt=0;
	for(ll i=2;i<maxn;++i)
	{
		if(!prime[i])
		{
			prime[i]=++cnt;
			for(ll j=i*i;j<maxn;j+=i)
			{
				prime[j]=1;
			}
		}
		else
		{
			prime[i]=prime[i-1];
		}
	}
	ll n;
	while(~scanf("%lld",&n))
	{
		printf("%lld\n",prime[n]);
	}
	return 0;
}

C++: #include <stdio.h>

void cnt(int i) {
	int j,k,l,m;
	l=0;
	m=0;
	for(j=1;j<=i;j++){
		for(k=1;k<=j;k++){
			if(j%k == 0){
				l++;
			}
		}
		if(l == 2){
			m++;
		}
		l=0;
	}
	printf("%d\n",m);
}

int main(void){
	int i;
	while (scanf("%d", &i) != EOF){
		cnt(i);
	}
}

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

int main()
{
	int n[30];
	int i=0;
	while(cin >> n[i]) {i++;}
		
	for (int k=0;k<i;k++){
		int s=1;
		for (int j=3;j<=n[k];j++){
			for(int m=2;m<j;m++){
				if(j%m==0){break;}
				if(m==j-1){s=s+1;}
			}
		}
		cout << s << endl;
	}	
    return 0;
}

C++: #include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=999999+5;
int prime[maxn];
bool is_prime[maxn];
int sieve(int n)
{
    int p=0;
    fill(is_prime,is_prime+n+1,true);
    is_prime[0]=is_prime[1]=true;
    for(int i=2;i<=n;i++)
    {
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}

int main()
{
    int n;
    while(cin>>n)
    {
        cout<<sieve(n)<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>

#define add push_back
#define inf 2147000000

#define rep(i,n) for(int i=0;i<n;i++)
#define out(a) cout<<a<<endl;

using namespace std;

int main(void){
	int sosuu[100000];
	int cont=0;
	int n;
	scanf("%d",&n);
	
	for(int i=2;i<=n;i++){
		for(int j=0;;j++){
			if(j==cont){
				sosuu[cont]=i;
				cont++;
				break;
			}
			if(i%sosuu[j]==0){
				break;
			}
		}
	}
	out(cont);
}

C++: #include <stdio.h>

bool isPrime(int n);

int main(void){
    int n;
    int primes;
    
    while (scanf("%d", &n)!=EOF){
        primes = 0;
        for (int i=2; i<=n; i++){
            if (isPrime(i)) primes++;
        }
        printf("%d\n", primes);
    }
}

bool isPrime(int n){
    if (n==1) return false;
    for (int t=2; t*t<=n; t++){
        if (n%t == 0) return false;
    }
    return true;
}