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>
using namespace std;

int main(){
	bool *map;
	string str;
	int n, cnt;

	while(1){
		cnt = 0;
		getline( cin, str );
		if( str.size()==0 )	break;
		sscanf(str.c_str(), "%d", &n);
		map = new bool[n+1];
		for( int i=2; i<=n; i++ ){
			map[i] = true;
		}

		for( int i=2; i<=n/2; i++ ){
			for( int j=2*i; j<=n; j+=i ){
				if( map[j] ){
					map[j] = false;
				}
			}
		}

		for( int i=2; i<=n; i++ ){
			if( map[i] ){
				cnt++;
			}
		}
		cout << cnt << endl;
		delete[] map;
		map = 0;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map> // pair
#include <set>
#include <string>

#define MAXSIZE 200000
#define PI 3.141592653589
using namespace std;

template<typename T>
T add(T a,T b){
  return a+b;
}

namespace A
{
  int f(void){
    return 1;
  }
}

int main(){
  int n;
  while (std::cin >> n) {
    int count=0;//素数の数
    for(int i=2;i<=n;i++){
      if(i==2){
        count++;
        continue;
      }
      int flag=0;
      for(int j=2;j<=sqrt(i);j++){
        if(i%j==0){
          flag=1;
        }
      }
      if(flag==0){
        count++;
      }
    }
    std::cout << count << '\n';
  }

}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define ll long long int
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  int i,j;

  while(scanf("%d", &n)!=EOF){

    if(n==1){
      cout<<"0"<<endl;
      continue;
    }else if(n==2){
      cout<<"1"<<endl;
      continue;
    }
    int sum=1;
    int prime[1000000]={};
    for(i=2;i<n;i++){
      if(prime[i]==0)
	for(j=2;j*i<n;j++){
	  if(prime[i*j]==0){
	    prime[i*j]=1;
	    sum++;
	  }
	}
    }
    cout<<n-sum<<endl;
  }

}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
bool sosu[1000010]={1,1,0};
int main(){
	for(int i=4;i<1000010;i+=2)sosu[i]=true;
	for(int i=3;i<1000010;i+=2)
		for(int j=i*3;j<1000010;j+=2*i)sosu[j]=true;
	
	int n;
	while(cin>>n){
		int co=0;
		loop(i,2,n+1)if(!sosu[i])co++;
		cout<<co<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
	int tmp;
	while (scanf("%d", &tmp) != EOF)
	{
		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;
	}

	return 0;
}

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

int prime(int n) {
	int k;
	if(n == 2) return 1;
	if(n % 2 == 0) return 0;
	for(k = 3; k * k <= n; k += 2) {
		if(n % k == 0) return 0;
	}
	return 1;
}

int cntPrime(int n) {
	int cnt = 0, i, k;
	for(i = 2; i <= n; i++) {
		cnt += prime(i);
	}
	return cnt;
}

int main() {
	int a;
	int arg[1024] = { 0 };
	int cnt = 0;
	while(scanf("%d", &a) != EOF) {
		arg[cnt++]=a;
	}
	int i;
	for(i = 0; i < cnt; i++) {
printf("%d\n", cntPrime(arg[i]));
	}
}

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

using namespace std;

bool p[10000000];
vector<int> prime;

void init(){
    memset(p,1,sizeof(p));
    p[0] = p[1] = false;
    for(int i = 2; i <= 1000000; i++){
        if(!p[i]) continue;
        for(long long j = 1LL*i*i; j <= 1000000; j += i)
            p[j] = false;
        prime.push_back(i);
    }
}

int CntPrime(int n){
    vector<int>::iterator it = lower_bound(prime.begin(), prime.end(), n);
    if( *it > n) it--;
    return (it - prime.begin() + 1);
}

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

C++: #include <iostream>
using namespace std;
const int MAX_V = 1000000; // 100????????§?´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????? 
int pcount[MAX_V+1];
int main() {
    int i, k, v,a,sum=0;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1; // 2??\????´???°??¨??????
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°2?????\????????°?´???°??§?????? 
            }
            
        } 
        
    }
    pcount[0]=0;
    pcount[1]=0;
    for(i=2;i<MAX_V;i++){
        if(prime[i]){
            sum++;
        }
        pcount[i]=sum;
    }
    while(1) {
        scanf("%d",&a);
        printf("%d\n",pcount[a]);
    } 

    return 0; 
    
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int whether(int num);
int count(int num);

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

int whether(int num){
    int s=sqrt(num);
    int i;
    
    for(i=3; i<=s; i+=2){
        if(num%i==0){ return 0; }
    }
    
    return 1;
}

int count(int num){
    int a=1;
    if(num<2){ return 0; }
    if(num==2){ return 1; }
    for(int i=3; i<=num; i+=2){
        if(whether(i)){ a+=1; }
    }
    
    return a;
}

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

int main()
{
	int n;
	int max;
	while(cin>>n)
	{
		max = sqrt(1.0*n);
		vector<bool> prime(n+1, true);
		prime[0]=false;
		prime[1]=false;
		for(int i=2; i<=max; ++i)
		{
			if(prime[i])
			{
				for(int j=i*2; j<=prime.size()-1; j+=i)
				{
					prime[j]=false;
				}
			}
		}
		cout << accumulate(prime.begin(), prime.end(), 0) << '\n';
	}
}