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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

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

using namespace std;


// cin >>
// cin <<
bool isPrime(int x){
	if(x==2) return true;
	if(x<2||x%2==0) return false;
	int i=3;
	while(i<=sqrt(x)){
		 if (x%i==0)return false;
		i= i+2;
	}
	return true;
}
int main(){
	int in[30]={};
	int out=0;
	for(int i=0;i<30;i++) cin >>in[i];
	for(int i=0;i<30;i++){
		if(in[i]==0){
			break;
		}else{
			out=0;
			for(int j=0;j<in[i]+1;j++){
				if(isPrime(j)==true){
					out++;
				}
			}
			cout <<out<<endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int PrimeNum(int n){
  for(int i = 2;i*i <= n;i++){
    if(i == n){
      return 1;
    }
    if(i*i == n){
      return 0;
    }
  }
}
int main(){
  int n,num;
   while(cin >> n){
    num = 0;
     for(int k = 2;k <= n;k++){
       if(PrimeNum(k) == 1){
	 num = num +1;
       } 
     }
     cout << num << endl;
     }
}

C++: #include <cstdio>
#include <memory.h>

int n;
int MAX_N=1000004;
bool DP[1000005] ;//素数リスト「素数じゃなかったらtrue」


int main()
{
	memset(DP,false,sizeof(DP));
	while(scanf("%d",&n)!=EOF)
	{
	 	int count=0;
		for(int i=1;i<=n;i++)
		{
			DP[0]=true;
			DP[1]=true;
			if(DP[i]==false)
			{
				count++;
				for(int j=i*2;j<MAX_N;j+=i)DP[j]=true;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: 
//  test.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    long j,s[1000000],d=1,i,n,k;
    
    for(i=3;i<1000000;i++){
        if(s[i]==0){
            
            for(j=2;j*j<i;j+=2){
                if(j%i==0)
                    break;
                if(j==2)
                    j=1;
            }
            
            if(j*j>=i){
                d++;
                for(k=2;k*i<1000000;k++){
                    s[k*i]=-1;
                }
            }
        }
        s[i] = d;
    }
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]-1);
    }
    
    
    return 0;
}

C++: #include<stdio.h>
int isprime(int n) {
	for(int i=2;i*i<=n;i++) {
		if(n%i==0) return 0;
	}
	return 1;
}

int main() {
	int n,p1,q1;
	while(1) {
		scanf("%d",&n);
		if(n==0) break;
		while(n>=5) {
			if(isprime(n)==1) {
				if(isprime(n-2)==1) {
					p1=n; q1=n-2;
					printf("%d %d\n",p1,q1);
					break;
				}
			}
			else n--;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

int prime[1000010];
bool is_prime[1000010];
void 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;
        }
    }
}

signed main(){
    sieve(1000000);
    int n;
    while(cin >> n){
        int ans = 0;
        rep(i, 2, n + 1){
            if(is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

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

constexpr int INSUU = 64;
constexpr int SOSUU = 1000000;

int Eratosthenes(int* primes){
  primes[0] = 2;
  primes[1] = 3;
  primes[2] = 5;
  primes[3] = 7;
  int prime_p = 4;
  for(int p = 11; p <= SOSUU; p+=2){
    bool is_prime = true;
    for(int i = 0; i < prime_p && primes[i] < 1000; i++){
      if((p % primes[i]) == 0){
	is_prime = false;
	break;
      }
    }
    if(is_prime){
      primes[prime_p++] = p;
    }
  }
  return prime_p;
}
int main(){
  int primes[SOSUU/2];
  int prime_count = Eratosthenes(primes);
  int n;
  while(cin >> n){
    int i = 0;
    for(; i < prime_count; i++){
      if(n < primes[i]){
	cout << i << endl;
	break;
      }
    }
    if(prime_count == i){
      cout << prime_count << endl;
    }
  }
}

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

int is_it_primeNum(int n)
{
	int a = 1;
	if (n == 0 || n == 1)
		return 0;
	else{ 
		for(int i=2;i<n;i++){
			if (n%i==0){
				a = 0;
				break;}
		}
	}
	return a;
}
int how_much_primeNum(int n)
{
	int ans = 0;
	for(int i=2;i<=n;i++){
		ans += is_it_primeNum(i);
	}
	return ans;
}

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

C++: 
//  test.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    long int j,s[1000000]={0},d=1,i,n,k;
    
    for(i=2;i<1000000;i++){
        if(s[i]==0){
            
            for(j=2;j*j<=i;j+=2){
                if(i%j==0)
                    break;
                if(j==2)
                    j=1;
            }
            
            
            if(j*j>i){
                d++;
                if(i<1000){
                    for(k=2;k*i<1000000;k++){
                        s[k*i]=-1;
                    }
                }
            }
        }
        s[i] = d;
    }
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]-1);
    }
    
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int N;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    vector<bool> is_prime(1000000,true);
    vector<int> prime(1000000,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i <= 1000000; ++i){
        if(is_prime[i]){
            ++p;
            for(int j = i*2; j <= 1000000; j += i) is_prime[j] = false;
        }
        prime[i] = p;
    }

    while(cin >> N){
        cout << prime[N] << '\n';
    }
    return 0;
}

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

using namespace std;

const int N = 1000000;

int num[N];

void init() {
	num[0] = num[1] = 0;
	for (int i=2; i<N; ++i) num[i] = 1;
	for (int i=2; i<1000; ++i) {
		if (num[i * i]) {
			int j = i + i;
			for (;j < N; num[j] = 0, j += i); 
		}
	}
	for (int i=1; i<N; ++i) num[i] += num[i-1];
}

int main() {
	int n;
	init();
	while (scanf("%d", &n) != EOF) {
		printf ("%d\n", num[n]);
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <cmath>
#define maxn 1000000
using namespace std;
int prime[maxn],number[maxn];
void getprime()
{
    int m=sqrt(maxn+0.5);
    for(int i=2;i<=m;i++)
    {
        if(!prime[i])
        {
            for(int j=i+i;j<maxn;j+=i)
            {
                prime[j]=1;
            }
        }
    }
    int sum = 0;
    for(int i=2;i<maxn;i++)
    {
        if(!prime[i])
        {
            sum++;
        }
        number[i]=sum;
    }
}
int main ()
{
    int n;
    getprime();
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",number[n]);
    }
}