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>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<'\n';}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;
tag:
m[i]=e;}}

C++: #include <bits/stdc++.h>
using namespace std;


bool prime[1000000];
int wei[1000000], sqrt_N = 1000;

int main()
{
  int N, i, j, k;

  for (i = 1; i <= 5; i += 4){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 4 * k * k + j * j) <= N; ++k){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 2; i <= 4; i += 2){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 3 * k * k + j * j) <= N; k += 2){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        if (N > 1000000)break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 3; i <= sqrt_N; i += 6){
    for (j = 1; j <= 2; ++j){
      for (k = j; k <= sqrt_N && (N = 4 * k * k + i * i) <= N; k += 3){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 5; i <= sqrt_N; ++i){
    if (prime[i]){
      for (j = i * i; j <= N; j += i * i){
        prime[j] = false;
      }
    }
  }
  prime[2] = prime[3] = true;

  for (i = 2; i < 1000000; ++i){
    wei[i] += wei[i - 1];
    if (prime[i]) wei[i]++;
  }

  while (~(scanf("%d", &N))) printf("%d\n", wei[N]);

  return 0;
}

C++: #include<iostream>
#include<cmath>

bool isPrime(int a){
	int x = std::sqrt((double)a);
	for(;x>1;x-=2)
		if(a%x == 0)
			return false;
	return true;
}

int countPrime(int a){
	int x = a,ans = 1;
	if(x%2==0)
		x--;
	for(; x>1; x-=2)
		if(isPrime(x))
			ans++;
	return ans;
}

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#define REP0(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
using namespace std;
typedef long long ll;
const ll ccc=1000000;
bool prime[ccc+1];
vector<ll> pr;
int main(){
	ll iii,jjj;
	for(iii=0;iii<=ccc;iii++){
		prime[iii]=true;
	}
	prime[0]=false;
	prime[1]=false;
	for(iii=2;iii*iii<=ccc;iii++){
		if(prime[iii]){
			for(jjj=2*iii;jjj<=ccc;jjj+=iii){
				prime[jjj]=false;
			}
		}
	}
	for(iii=2;iii<=ccc;iii++){
		if(prime[iii]){
			pr.push_back(iii);
		}
	}
	int a;
	while(scanf("%d",&a)!=EOF) printf("%d\n",upper_bound(ALL(pr),a)-pr.begin());
	return 0;
}

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

bool primes[1000000];

void Sieve(){
    for(int i= 2; i < 1000000; i++){
        primes[i] = true;
    }
    primes[1] = false;    
    for(int i = 2; i < 1000; i++){
        if(primes[i] == true)
            for(int j=i; j*i < 1000000;j++){
                primes[j*i] = false;
            }
    }     
}
bool IsPrime(int x){
    return primes[x];
}

int main(void){
    Sieve();
    int n, c;
    while(cin >> n){
        c = 0;
        for(int i = 2; i <= n; i++){
        if(IsPrime(i)==true)
            c++;
        }
        cout << c << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>

using namespace std;

#define MAX_VALUE 1000000

int get_numprime( int num );

int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		int result = get_numprime( num );
		cout << result << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はカウント済み

	bool erat[MAX_VALUE] = {0};

	for( int i = 0 ; i < num+1 ; i++ )
	{
		erat[i] = true;
	}
	erat[0] = false; erat[1] = false;
	for( int i = 2 ; i <= num ; i++ )
	{
		if( erat[i] )
		{
			for( int j = i*2 ; j <= num ; j+=i )
			{
				erat[j] = false;
			}
		}
	}
	for( int i = 3 ; i <= num ; i+=2 )
	{
		if( erat[i] ) numprime++;
	}

	if( num == 1 ) numprime = 0;

	return numprime;
}

C++: #include <bitset>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    bitset<999999 + 1> b;
    auto t = b;
    t.set();
    t[0] = false;
    t[1] = false;
    int i = 0;
    while (true) {
        bool done = false;
        while (!t[i]) {
            ++i;
            if (i == t.size()) {
                done = true;
                break;
            }
        }
        if (done) {
            break;
        }

        b[i] = true;
        for (int j = i; j < t.size(); j += i) {
            t[j] = false;
        }
    }

    string s;
    while (getline(cin, s)) {
        int n = stoi(s);
        int count = 0;
        for (int j = 1; j <= n; ++j) {
            if (b[j]) {
                ++count;
            }
        }
        cout << count << endl;
    }
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    ll n;
    while(cin>>n){
        vector<bool> ip;
        if(ip.size()<n+1){
            ip.resize(n+1,true);
        }
        ip[0]=false;
        ip[1]=false;
        for(int i=2;i<=(n+1)/2;i++){
            for(int j=2;i*j<n+1;j++){
                ip[i*j]=false;
            }
        }
        ll ans=0;
        for(int i=0;i<n+1;i++){
            if(ip[i])ans++;
        }
        
        
        cout<<ans<<endl;
        
        
        
    }





return 0;
}

C++: #include <stdio.h>
#include <math.h>
int check_prime(int a)
{
   int c,b;
   b = (int)sqrt(a);
   for ( c = 2 ; c <=  b; c++ )
   {
      if ( a%c == 0 )
        return 0;
   }
      return 1;
}

int main ()
{
    int  n=0,i=0,prime=0,result=0;

   while( scanf("%d",&n) != EOF)
{
 for(i=2;i<=n;i++)
 {

   result = check_prime(i);

   if ( result == 1 )
     prime = prime +1;
 }
 printf("%d",prime);
 printf("\n");
 prime=0;
}
 return 0;
}

C++: #include<stdio.h>
int main(){
	int a,b,n;
	int p[80000];
	p[0]=2;
	n=1;
	for(a=3;a<1000000;a++){
		for(b=0;b<n;b++){
			if(a%p[b]==0){break;}
			if(a<p[b]*p[b]){
				p[n]=a;
				n++;
				break;
			}
		}
	}
		scanf("%d",&a);
		n=0;
		while(a>=p[n]){
			n++;
		}
		if(a<2){n=0;}
		printf("%d\n",n);
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool b[1000000];
int n,i,j,ans;
int GCD(int x,int y)
{
	return y==0?x:GCD(y,x%y);
}
void biao()
{
	for(i=2;i<=999999;i++)
	{
		if(b[i]==0)
		for(j=i+i;j<=999999;j=j+i)
			b[j]=1;
	}
}
int main()
{
	biao();
	while(~scanf("%d",&n))
	{
		ans=0;
		for(i=2;i<=n&&i<5;i++)
		{
			if(b[i]==0)
				ans++;
		}
		for(i=5;i<=n;i=i+6)
		{
			if(b[i]==0)
				ans++;
			if(b[i+2]==0&&i+2<=n)
				ans++;
		}
		printf("%d\n",ans);
	}
}