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++: //
// エラトステネスの篩
//
// cf.
//   高校数学の美しい物語: エラトスネテスの篩
//     https://mathtrain.jp/eratosthenes
//
// verified
//   AOJ 0009 素数
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp
//

/*
 
    n 以下の素数をすべて列挙する
 
*/


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


vector<bool> isprime;
vector<int> Era(int n) {
    isprime.resize(n, true);
    vector<int> res;
    isprime[0] = false; isprime[1] = false;
    for (int i = 2; i < n; ++i) isprime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (isprime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) isprime[j] = false;
        }
    }
    return res;
}


int main() {
    vector<int> primes = Era(1000000);
    int n;
    while (cin >> n) {
        int num = upper_bound(primes.begin(), primes.end(), n) - primes.begin(); // n 以下が何個か
        cout << num << endl;
    }
}

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

int main(void){
	int n;
	
	int i,j;
	int count = 0;
	int Flag = 0;
	
	while(scanf("%d",&n) != EOF){
		for(j = 2;j <= n;j++){
			for(i = 1;pow(i,2) <= j;i++){
				if(j % i == 0&&i != 1){
					Flag = 1;
					break;
				}
			}
			if(Flag != 1){
				count++;
			}
			Flag = 0;
		}
		printf("%d\n",count);
		count = 0;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
   vector<int> v(1000000,0),rui(1000000,0);
   rep(i,1,999999)if(isPrime(i))v[i]=1;
   rui[1]=v[1];
   rep(i,2,999999)rui[i]=rui[i-1]+v[i];
   
   int n;
   while(cin>>n){
       cout<<rui[n]<<endl;
   }
   
    
    return 0;
}

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

using namespace std;

long store[999999];
//long storage[999999];
//int index=1;
bool IsPrime(long prime){
    if(prime==store[prime]){
        /*if(storage[index]!=0){
            storage[index]=storage[index]+1;
            index++;
        }*/
        return true;
    }
    //storage[index]=storage[index-1];
    //index++;
    bool ans=false;
    if(prime==2){
        store[prime]=prime;
        return true;
    }
    if(prime==3){
        store[prime]=prime;
        return true;
    }
    for(long i=2;i<=sqrt(prime);i++){
        if(prime%i==0) {
            return false;
        }
        else ans=true;
    }
    if(ans==true)   store[prime]=prime;
    return ans;
}

int main(){
    long n;

    //memset(storage,0,999999);
    while(scanf("%d",&n)==1){
        memset(store,-1,999999);
        long count=0;
        for(long i=n;i>0;i--){
            /*if(storage[i]!=0){
                count=count+storage[i];
                break;
            }*/
            if(IsPrime(i)==true)    count++;
        }
        printf("%ld\n",count);
    }

    return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <stdio.h>
#include <vector>;
using namespace std;
const int maxn = 1e6+100;
bool prim[maxn];
vector <int> ve;

void get_prim() {
    prim[0] = prim[1] = true;
    for(int i=2;i<maxn;i++) {
        if(prim[i])
            continue;
        ve.push_back(i);
        for(int j=i*2;j<maxn;j+=i) {
            prim[j] = true;
        }
    }
}

int main() {
    int n;
    get_prim();
    while(scanf("%d",&n) != EOF) {
        int pos = lower_bound(ve.begin(),ve.end(),n) - ve.begin();
        if(ve[pos] > n)
            pos--;
        printf("%d\n",pos+1);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int n;
int max=1;
while(cin>>n){
for(int i=3;i<=n;i+=2){
for(int j=2;j<=i/2+1;j++){
if(i%j==0){max++;goto A;}
}
A:
;
cout<<max<<endl;
max=1;
}
}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

ll eratosthenes(ll x){
    vbo isprime(x+1,true);
    isprime[0]=false;
    isprime[1]=false;
    ll p=0;
    for(ll i=2;i<=x;i++){
        if(isprime[i]){
            p++;
            for(ll j=2*i;j<=x;j+=i)isprime[j]=false;
        }
    }
    return p;
}

int main(){
    queue<int> q;
    int n;
    while(cin>>n)q.push(eratosthenes(n));
    while(q.size()){
        cout<<q.front()<<endl;
        q.pop();
    }
}

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

using namespace std;

int sosuu(int n);

int main(){
    int n=0;
    int num=0;
    int a[30]={0};
    int max=0;
    while(scanf("%d",&n)!=EOF){
        if(max<n){
            max=n;
        }
        a[num]=n;
        num++;
    }
    
    int b[max];
    for(int i=0; i<max; i++){
        b[i]=i;
    }
    b[1]=0;
    
    for(int i=2; i<sqrt(max); i++){
        for(int j=i+1; j<max; j++){
            if(j%i==0){
                b[j]=0;
            }
        }
    }
    for(int i=0; i<num; i++){
        int temp =a[i];
        a[i]=0;
        for(int j=0; j<=temp; j++){
            if(b[j]!=0){
                a[i]++;
            }
        }
        cout<<a[i]<<"\n";
    }
    
    
}
int sosuu(int n){
    if(n==2){
        return 1;
    }else{
        int temp=1;
        for(int i=0; i<n; i++){
            temp=temp*2;
        }
        if(temp%n!=2%n){
            return 0;
        }
        return 1;
    }
}

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

int main()
{
	int n;
	
	while (cin >> n)
	{
		int ans = 0,rootn;

		int a[INF] = {0};
		
		rootn = sqrt(n)+1;
	
		for (int i = 2; i <= rootn; i++)
		{
			if (a[i]==0)
			{
				for (int j = i+1; j <= INF; j++)
				{
					if (a[j] == 0 && j%i == 0)
					{
						a[j] = 1;
					}
				}
			}
		}
		cout << "a" << endl;
		for (int i = 2; i <= n; i++)
		{
			if (a[i]==0)
				++ans;
		}
		cout << ans << endl;
	}
			
	return 0;
}