Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

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

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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 j = (long long int)i*(long long int)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(void)
{
	int n;
	int pnum;
	
	while (cin >> n){
		int ct  = 0;
		for (int i = 2; i <= n; i++){
			for (pnum = 2; pnum <= n; pnum++){
				if (i % pnum == 0){
					break;
				}
			}
			if (i == pnum){
				ct++;
			}
		}
		cout << ct << endl;
	}
	
	return (0);
}

C++: #include<iostream>

#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)


using namespace std;



int main(){
	bool prime[1000001];
	rep(i, 1000001){
		prime[i] = true;
	}
	prime[0] = prime[1] = false;
	
	loop(i, 2, 1001){
		if (prime[i]){
			for (int j = i * 2; j < 1000001; j += i){
				prime[j] = false;
			}
		}
	}



	int ord;
	while (cin >> ord){
		int cnt=0;
		rep(i, ord + 1){
			if (prime[i]){
				cnt++;
			}
		}
		cout << cnt << endl;
		cnt = 0;
	}


}

C++: #include <stdio.h>

int main(){
	int sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z,d=0;
	while (scanf("%d", &n) != EOF){
		z = 0;
		if(d < n)
		{for (i = 3; i < n; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++; d = i; }
			}
		}
	}
		for (i = 0; i < n; i++){ if (sosuu[i] > n + 1)break; z++; }printf("%d\n", z);
	}
	return 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;
}