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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

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

using namespace std;

bool isprime(int n)
{
	for (int i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0) return false;
	}

	return true;
}

int main()
{
	int N;

	int C = 0;

	cin >> N;

	for (int i = 2; i <= N; i++)
	{
		if (isprime(i) == true)
		{
			C += 1;
		}
	}

	cout << C << endl;

	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int t[999999];

    return 0;
}

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

int main(void) {
	vector<int> v;
	v.push_back(2);
	v.push_back(3);
	int i, j;
	bool flag;
	for (i = 5; i < 999999; i++) {
		flag = true;
		for (j = 2; j <= sqrt(i); j++) {
			if (i % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			v.push_back(i);
		}
	}
	int n;
	while (cin >> n) {
		i = distance(v.begin(), lower_bound(v.begin(), v.end(), n));
		if (v[i] == n)
			cout << i + 1 << endl;
		else 
			cout << i << endl;
	}

}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int time;
	vector<int> v;
	v.push_back(2);
	v.push_back(3);
	while(cin>>time){
		int abcd=0;
		if(time>v[v.size()-1]){
			for(int abc=1+v[v.size()-1];abc<=time;abc+=2){
				for(int bcd=0;bcd<(int)v.size() ;bcd++){
					if(abc%v[bcd]==0){
						goto end;
					}
				}
				v.push_back(abc);
				end:;
			}
		}
		for(int abc=0;v[abc]<=time;abc++){
			abcd++;
		}
		cout<<abcd<<endl;
	}
	return 0;
}

C++: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<int> prime(0);//i番目の素数
vector<bool> is_prime(0);//iは素数か
//n以下の素数の数
int hurui(int n){
    is_prime.resize(n+1,true);
    is_prime[0]=0; is_prime[1]=0;
    int p=0;
    REP(i,2,n+1){
        if(is_prime[i]){
            prime.emplace_back(i);
            p ++;
            for(int j=2*i; j<=n; j +=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
  hurui(1e7);
  int n;
  while(cin>>n){
      cout<<upper_bound(all(prime),n)-prime.begin()<<endl;
  }
}

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

int main(){
    int n;
    while(cin >> n){
        int numOfPrime = 0;
        bool isPrime[n-1];
        for(int i=2;i<=n;++i){
            isPrime[i-2] = true;
        }
        for(int i=2;i<=sqrt(n);++i){
            if(!isPrime[i-2]){
                continue;
            }
            for(int j=i;j<=n;++j){
                if(j%i == 0 && i != j){
                    isPrime[j-2] = false;
                }
            }
        }
        for(int i=2;i<n;++i){
            if(isPrime[i-2]){
                ++numOfPrime;
            }
        }
        cout << numOfPrime << endl;
    }
}

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>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    vector<int> prime;
    int n;
    for(int i=2;i<1000000;i++){
        bool isprime=true;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                isprime=false;
                break;
            }
        }
        if(isprime) prime.push_back(i);
    }
    while(cin >> n){
        for(int i=0;i<prime.size();i++){
            if(prime[i]>n){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

using namespace std;

int main(){
  int n, count,j;
  int limit;
  vector<int> nl;
  while(cin >> n){
    nl.push_back(n);
  }

  for(int i=0; i<nl.size(); i++){
    n = nl[i];
    int prime[n+1];
    for(j=2; j<=n; j++){
      prime[j] = 1;
    }
    count = 0;
    limit = (int)sqrt(n);
    for(j=2; j<=limit; j++){
      if(prime[j] == 1){
        for(int k=j*2; k<=n; k+=j){
          prime[k] = 0;
        }
      } 
    }

    for(j=2; j<=n; j++){
      if(prime[j]==1){
        count++;
      }
    }
    cout << count << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	long long n;
	while(cin >> n){
		long long sum;
		if (n == 1)sum = 0;
		else {
			sum = 1;
			for (int i = 4; (i - 1) < n + 1; i += 4) {
				if (isprime(i - 1))sum++;
				if (isprime(i + 1))sum++;
			}
		}
		cout << sum << '\n';
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int kk[10*10];
 
 bool isPrime(int x)
 {
   for(int i=3;i<=(int)(sqrt(x));i=i+2) 
   {
     if(x%i==0) return false;        
   }    
   return true;
 }
 
 int main()
 {
   int n;
   while(cin>>n)
   {
      if(n==1) cout<<"0"<<endl;
      else if(n==2) cout<<"1"<<endl;
      else
      {
        int count=1;
        for(int i=3;i<=n;i++) if(isPrime(i)) count++;
        cout<<count<<endl;
      } 
   }
   //while(1);      
   return 0;    
 }

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

using namespace std;

bool isprime(int n) {
	if (n < 2)
		return false;
	int lim = (int)sqrt((double)n);
	for (int i = 2; i <= lim; i++)
		if (!(n%i))
			return false;
	return true;
}

int main(void) {
	int n;
	while (cin >> n) {
		int total = 0;
		for (int i = 2; i <= n; i++) {
			if (isprime(i))
				total++;
		}
		cout << total << endl;
	}
	return 0;
}

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

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}


int main(){
int n;
while (cin>>n){
	int yakusu=0;
	for (int i=2;i<=n;i++){
		bool flag=true;
		for (int j=2;j<i-1;j++){
			if(i%j==0){
				flag=false;
			}
		}
		if (flag){
		yakusu++;
		}

	}
cout<<yakusu<<endl;
}
return 0;
}