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++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

int const N = 1000010;
int ans[N];

bool isprime(int x){
    for (int i = 2; i*i <= x; i++){
        if (x%i == 0) return false;
    }
    return true;
}

int main(int argc, char ** argv) {
    ans[0] = ans[1] = 0;
    for (int i = 2; i < N; ++i) {
        if (isprime(i)) ans[i] = ans[i - 1] + 1;
        else ans[i] = ans[i - 1];
    }
    int n;
    while (~scanf("%d\n", &n)){
        printf("%d\n",ans[n]);
    }
}

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

int isPrime(int a){
	int i;     
	int isTrue;     
	for(i = 3, isTrue = 1; i < a; i+=2){ 
		if( !(a%i) ){ isTrue = 0; break; } 
	}     
	return a==2||isTrue&&a%2; 
}   

int main(){
	int n,ans=0;
	while(cin >> n){
		for(int i = 2; i <= n; i++){
			if(isPrime(i))ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: import math

def check_prime(goal):
    true_or_false=False
    for i in range(2,int(math.sqrt(goal))+1):
        if goal%i==0:
             true_or_false=True
    if true_or_false==False:
        return True
    else:
        return False
anss=[]
while True:
    try:
        num=int(input())
        num_of_prime=0
        for i in range(2,num+1):
           if check_prime(i):
               num_of_prime+=1
        anss.append(num_of_prime)
    except:
        break

for ans in anss:
    print(ans)

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

bool p[1000000];

int main()
{
  for(int i=2;i*i<1000000;i++)if(!p[i])for(int j=i+i;j<1000000;j+=i)p[j]=1;
  p[0]=p[1]=1;
  int n;
  while(cin>>n){
    int ans=0;
    rep(i,n)if(!p[i])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

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

bool nArray[999999];

int main() {
    int n = 0;
    for (int cou = 0; ((scanf("%d", &n) != EOF) && (cou < 30)); ++cou) {
        for (int i = 0; i < 999999; ++i) {
            nArray[i] = (i <= 1) ? false : true;
        }

        int maxValue = sqrt(n);
        for (int i = 2; i <= n + 1; ++i) {
            if (!nArray[i]) {
                continue;
            }

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

        int result = 0;
        for (int i = 0; i <= n; ++i) {
            if (nArray[i]) {
                result++;

            }
        }

        printf("%d\n", result);
    }

    return 0;
}

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

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

	while( cin >> n ){		
		ans = 0;
		for(int i=0 ; i<=n ; i++){
			if(p[i]){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

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


int main() {

//変数の宣言

	vector<int> prime;
	int i,n,j;
	
	cin >> n;
	prime.push_back(2);
	
	for(i=3;i<n+1;i++){
		for(j=0;j<prime.size();j++){
			if (i%prime[j]==0) break;
			if (j==prime.size()-1) {
				prime.push_back(i);
			}
		}
	}
	
	/*
	for(i=0;i<prime.size();i++){
		cout << prime[i] <<endl;
	}
	*/
	cout << prime.size() <<endl;
	

	return 0;
}

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

int main() {
  vector<bool> isPrime(MAX, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i * i < MAX; i++) {
    if (isPrime[i]) {
      for (int j = 2; i * j < MAX; j++) {
        isPrime[i * j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int ans,n,i,k;
	while(1){
		ans=0;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			cout<<0<<endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=9){
				for(i=9;i<=n;i+=2){
				    int prime=1;
				    for(k=3;k<=sqrt(i);k+=2){
					    if(k==3||k%3!=0){
					        if(i%k==0){
						            prime=0;
						            break;
					        }
    					}
					}
				    if(prime)ans++;
				}
			}
		cout<<ans<<endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;



int erat(int num){
int i,cnt=1;
//	vector<int> Prime(num+2); // 素数リスト
	if(num<2) return 0;
	vector<char> Find(num+2); // 探索リスト
	for(int i = 2; i <= num; i++) Find[i] = '0';
	for(int i = 2; i*i < num; i++){
    	if(Find[i] > '0') continue; // すでに除いた数は飛ばす

    // j++からj+=iになったのでループ内でiの倍数のみが処理される。だいぶ高速化
    	for(int j = i * 2; j< num; j += i) {
        	if(Find[j]=='0') Find[j] = '1';
    	}
	}
// 2の倍数の素数は2だけなので奇数のみを判定
//	Prime.push_back(2);
//	for(int i = 3; i*i < num; i += 2){
//    	if(Find[i]='0') Prime.push_back(i);
//	}
	rep2(i,3,num) if(Find[i]=='0' && i % 2) { cnt++;}
	return cnt;
}

int main(void){

int num;

	while(cin >> num){
//		cnt = erst(num);
		cout << erat(num) <<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int num[999999]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=999999;i++)
	num[i]=1;
for(int i=2;i<=1001;i++){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

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

const long MAX_N=10000000;
bool isPrime[MAX_N];

int main(){
	//素数テーブルの設定
	for(long i=2; i<=MAX_N; ++i)
		isPrime[i]=true;
		
	for(long i=2; i<=MAX_N; ++i){
		if(isPrime[i]){
			for(long j=2; i*j<=MAX_N; ++j) isPrime[i*j]=false;
		}
	}
	
	//実際の問題処理
	long n;
	
	while( scanf("%ld", &n) != EOF ){
		long count=0;
		
		for(long i=2; i<=n; ++i){
			if(isPrime[i]) ++count;
		}
		
		printf("%ld\n", count);
	}	 

	return 0;
}

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

int N;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    vector<bool> is_prime(1000000,true);
    vector<int> prime(1000000,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i <= 1000000; ++i){
        if(is_prime[i]){
            ++p;
            for(int j = i*2; j <= 1000000; j += i) is_prime[j] = false;
        }
        prime[i] = p;
    }

    for(int i = 0; i <= 30; ++i){
        cin >> N;
        cout << prime[N] << '\n';
    }
    return 0;
}