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>
using namespace std;
#define MAX 1000000

int main()
{
    int prime[MAX-1], S[MAX-1];
    for (int i = 0; i < MAX; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++)
    {
        if (prime[i] != 0)
        {
            for (int j = 2 * i; j < MAX; j += i)
            {
                prime[j] = 0;
            } } }
        
        
    for (int i = 1; i < MAX; i++)
    {
        S[i] = prime[i] + S[i - 1];
    }
    S[0] = prime[0];
    int N;
    while (cin >> N)
    {
        cout << S[N] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

using namespace std;

int main()
{
	int p[10000];
	int c=0,flag,n;
	long long ans;

	p[c++]=2;p[c++]=3;p[c++]=5;

	for(int i=7;i*i<999999;i++){
		flag=1;
		for(int j=0;j<c;j++){
			if(i%p[j]==0){flag=0;break;}
		}
		if(flag) p[c++]=i;
	}

	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(int i=0;p[i]<=n;i++) ans++;
		cout<<ans<<endl;
	}


	return 0;
}

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

int solve(int n) {
	vector<bool> v;
	vector<int> prime;
	if (n == 0)return 0;
	else if (n == 1)return 0;
	else if (n == 2)return 1;
	else {
		v.push_back(false);//0
		v.push_back(false);//1
		for (int i = 2; i <= n; i++) {
			v.push_back(true);
		}
		for (int i = 2; i <= (int)pow(n, 0.5) + 1; i++) {
			if (v[i] == true) {
				for (int j = i * 2; j <= n; j += i) {
					v[j] = false;
				}
			}
		}
		//cout << "v.size()=" << v.size() << endl;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == true) {
				prime.push_back(i);
			}
		}
		return prime.size();
	}

}

int main()
{
	int n;
	while (cin >> n) {
		int ans = solve(n);
		cout << ans << endl;
	}

    return 0;
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int prime[INF];
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;

  REP(i, INF) prime[i] = 1;

  prime[0] = prime[1] = 0;

  for (int i =  2; i * i <= INF; i++){
    if (prime[i]){
      for (int j = 2; i * j <= INF; j++){
        prime[i * j] = 0;
      }
    }
  }

  while (cin >> n, n){
    int ct = 0;
    for (int i = 2; i <= n; i++){
      if (prime[i]) ct++;
    }
    cout << ct << endl;
  }
}

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


int main() {

//変数の宣言

	int i,n,j,sum,judge=1;
	
	while(cin>>n){
		sum = 1;
		for(i=3;i<n+1;i+=2){
			for(j=3;j<=sqrt(i);j+=2){
				if(i%j==0){
					judge = 0;
					break;
				}
			}
			if (judge==1){
				sum++;
			}
			judge = 1;
		}
		
		cout << sum <<endl;
	}

	return 0;
}

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

vector<int>memo;

bool isprime(int q){
	if(q==2){
		return true;
	}else if(q%2==0){
		return false;
	}else{
		int max=sqrt(q);
		for(int i=3;i<q;i=i+2){
			if(q%i==0)return false;
		}
		return true;
	}
}

int main(){
	int n;
	while(cin>>n){
		if(n+1>memo.size())memo.resize(n+1);
		int sum=0;
		for(int i=2;i<=n;i++){
			if(memo[i]==1){
				sum++;
				continue;
			}else if(memo[i]==-1){
				continue;
			}else if(isprime(i)){
				sum++;
				memo[i]=1;
			}else{
				memo[i]=-1;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

const int m=500000;
int prime[m];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<m; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<m; j+=i) prime[j]=0;
    }
    for(int i=1; i<m; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        if(n<2) cout<<"0\n";
        else cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}

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

int main(){

	int n, i, j, prmnum;
	bool prm = true;
	while(cin>>n){
		prmnum = 1;

		for( i=3;i<=n;i+=2 ){
			prm = true;

			for( j=3;j<=sqrt((double)i);j+=2 ){
				if( i%j == 0 ){
					prm = false;
					break;
				}
			}


			if(prm)prmnum++;
		}


		cout << prmnum << endl;
	}
	return 0;
}

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

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	int n;
	cin>>n;
	int count=0;
	for(int i=0;i<=n;i++){
		if(prime[i]==1){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n,s,a;
	
	while(cin >> n){
		a=1;
		for(int j=3;j<=n;j+=2){
			s=0;
			for(int i=3;i<j;i+=2){
				if(j%i==0){
					s=1;
					break;
				}
			}
			if(s==0){
				a++;
			}
		}
		cout << a << "\n";
	}
		
	
return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){

	int i, j, k;
	int n;

	while(cin >> n){

		int count = 0;

		if(n>2){
			count ++;
			for(i=3 ; i<=n ; i+=2){
				for(j=3 ; j<=(int)sqrt(i) ; j+=2){
					k = i % j;
					if(k == 0) break;
				}
				if(j > (int)sqrt(i)) count ++;
			}
		}
		cout << count << endl;

	}


	return 0;
}

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

int main(){
  int n,i,j;
  while(cin >> n) {
    if(n==1){
      cout << 0 <<endl;
      continue;
    }
    int k = 0, a[n];
    a[0] = 2;
  
    for (i = 3; i <= n; i = i + 2) {
      for (j = 0; j <= k; j++) {
        if(i % a[j] == 0 ) break;
        if(i <= a[j] * a[j]) {
          k++;
          a[k] =i;
          break;
        }
        
      }
      if(j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    cout << k+1 << endl;
  }
  
  return 0;
}