Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

int main(){
	bool is_prime[100000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<100000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<100000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<100000;j+=i){
				is_prime[j]=false;
				}
			}
		}
		
		int n_prime[100000];
		
		int cnt=0;
		for(int i=0;i<100000;i++){
			if(is_prime[i]){
				cnt++;
			}
			n_prime[i]=cnt;
		}
		
		while(true){
			int n;
			cin>>n;
			if(cin.eof())
				break;
				
			cout<<n_prime[n]<<endl;
		}
		
		return 0;
}

C++: #include <iostream>

using namespace std;

int vtoad(int);

int main(void){
	char	*val;
	int	c,N,ad;

	while(cin >> N){
		c=2;
		if(N==1||N==2)
			c=N-1;
		else{
			val = new char[N/3+2];
			for(int i=0;i<N/3+2;i++)
				val[i]=0;

			for(int i=1;i*6-1<=N;i++)
				for(int j=-1;j<=1;j+=2)
					if(i*6+j<=N&&(ad=vtoad(i*6+j)))
						if(!val[ad]){
							c++;
							for(int k=2;(i*6+j)*k<=N;k++)
								if(ad=vtoad((i*6+j)*k))
									val[ad]=1;
					}
			delete [] val;
		}
		cout << c << endl;
	}

	return 0;
}

int vtoad(int val){
	if(!((val+1)%6))
		return (val+1)/3-1;
	else if(!((val-1)%6))
		return (val-1)/3+2;
	else
		return 0;
}

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

int main()
{
  int n;
  int count=0;
  while(cin >> n){
    double nd=(double)n;
    int root=(int)sqrt(nd);
    
    for(int i=2;i<=n;i++){
      for(int j=2;j<=root;j++){
        if(i%j==0) break;
      }
      if(j==root) count++;
    }
    cout << count << endl;
  }
  
  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	int i, k, v;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	for(i=0;i<30;i++){
		scanf("%d", &v);
		int count = 0;
		for(i=0;i<=v;i++){
			int isprime = prime[i];
			if(isprime) count ++;
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
bool us[1000010]={false};
int p[1000010] = {0};
int main(){
	/*Eratosthenes*/
	p[0] = 2;
	for(int i = 0; i <= 1000010; i+=2){
		us[i] = true;
	}
	
	int cnt = 1;
	for(int i = 3; i <= 1000010; i+=2){
		int q = 0;
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[cnt] = i;
			cnt++;
			us[i] = true;
			q = i;
			for(int j = q+q; j <= 1000010; j += q){
				us[j] = true;
			}
		}
	}
	
	int n;
	while(~scanf("%d",&n)){
		int x = 0;
		while(1){
			if(p[x] > n)break;
			x++;
		}
		printf("%d\n",x);
	}
	return 0;
}

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

int main(){
	using namespace std;
	while(1){
		int n,i,j=2,count = 0,limit;
		cin >> n;
		if (cin.eof() || n == 0) break;
		int prime[n+1];
		for(i=2;i<=n;i++) prime[i] = 1;
		limit = sqrt(n);
		for(i=2;i<=limit;i++){
			if(prime[i] == 0) continue;
			else{
				for(j=2*i;j<=n;j++){
					if(j%i == 0) prime[j] = 0;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(prime[i] == 1) count += 1;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
//#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

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

int main(){
	long long int prime[500];
	long long int ptr=0;
	
	prime[ptr++]=2;
	prime[ptr++]=3;

	for(int no = 5 ; no <= 1000 ; no += 2){
		int flag = 0;
		for (int i = 1; prime[i] * prime[i] <= no ; i++){
			if(no % prime[i] == 0){
				flag=1;
				break;
			}
		}
		if(!flag)
			prime[ptr++] = no;
	}
	
	
	int n,co=0;
	while(cin>>n){
		co=0;
		for(int i=0; prime[i] <= n ;i++){
			co++;
		}
		cout<<co <<endl;
	}
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		vector<int> number(1000000,0);
		int ans=0;

		for(int i=2;i<=n;i++){
			if(number[i]==0){
				ans++;
				//cout<<i<<endl;
				for(m=i;m<=n;m+=i){
					number[m]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
using namespace std;
main(){
	while(cin>>n){
		cout<<n<<endl;
	}
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[1000000];
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	for(int i=2;i<1000000;i++){
		for(int j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}
	int n,cnt=0;
	while(cin>>n){
		cnt=0;
		rep(i,n+1){
			if(prime[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
int* table =  new int[1000000];
while(~scanf("%d",&n)){

fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i*i<=n;i++){
if(table[i] && !is_prime(i)) {
for(int j=i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

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

static void InputData(std::vector<int>& v)
{
	int n = 0;

	if (0x00 == &v) {
		std::cerr << "vec is null" << std::endl;
		return;
	}
	while (std::cin >> n) {
		v.push_back(n);
	}
}

static int getPrimeNumber(int n)
{
    int cnt = 0;

    for (int i = 2; i <= n; i++) {
	for (int j = 2; j <=i; j++) {

	    if (i == j) {
		cnt++;
	    }
	    if (0 == i % j) {
		break;
	    }
	}
    }

    return cnt;
}

static bool printPrimeNumber(std::vector<int>& v)
{
	if (0x00 == &v) {
		std::cout << "v is null" << std::endl;
		return false;
	}
	for (int i = 0; i < v.size(); i++) {
		std::cout << getPrimeNumber(v.at(i)) << std::endl;
	}

	return true;
}

int main()
{
	std::vector<int> vec;

	InputData(vec);
	printPrimeNumber(vec);

	return 0;
}