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>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

using namespace std;

int main()
{
	int p[10000];
	int c=0,flag,n;
	long long ans;

	p[c++]=2;p[c++]=3;p[c++]=5;

	for(int i=7;i*i<999999;i++){
		flag=1;
		for(int j=0;j<c;j++){
			if(i%p[j]==0){flag=0;break;}
		}
		if(flag) p[c++]=i;
	}

	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(int i=0;p[i]<=n;i++) ans++;
		cout<<ans<<endl;
	}


	return 0;
}

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

int solve(int n) {
	vector<bool> v;
	vector<int> prime;
	if (n == 0)return 0;
	else if (n == 1)return 0;
	else if (n == 2)return 1;
	else {
		v.push_back(false);//0
		v.push_back(false);//1
		for (int i = 2; i <= n; i++) {
			v.push_back(true);
		}
		for (int i = 2; i <= (int)pow(n, 0.5) + 1; i++) {
			if (v[i] == true) {
				for (int j = i * 2; j <= n; j += i) {
					v[j] = false;
				}
			}
		}
		//cout << "v.size()=" << v.size() << endl;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == true) {
				prime.push_back(i);
			}
		}
		return prime.size();
	}

}

int main()
{
	int n;
	while (cin >> n) {
		int ans = solve(n);
		cout << ans << endl;
	}

    return 0;
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int prime[INF];
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;

  REP(i, INF) prime[i] = 1;

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

  for (int i =  2; i * i <= INF; i++){
    if (prime[i]){
      for (int j = 2; i * j <= INF; j++){
        prime[i * j] = 0;
      }
    }
  }

  while (cin >> n, n){
    int ct = 0;
    for (int i = 2; i <= n; i++){
      if (prime[i]) ct++;
    }
    cout << ct << endl;
  }
}

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


int main() {

//変数の宣言

	int i,n,j,sum,judge=1;
	
	while(cin>>n){
		sum = 1;
		for(i=3;i<n+1;i+=2){
			for(j=3;j<=sqrt(i);j+=2){
				if(i%j==0){
					judge = 0;
					break;
				}
			}
			if (judge==1){
				sum++;
			}
			judge = 1;
		}
		
		cout << sum <<endl;
	}

	return 0;
}

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

vector<int>memo;

bool isprime(int q){
	if(q==2){
		return true;
	}else if(q%2==0){
		return false;
	}else{
		int max=sqrt(q);
		for(int i=3;i<q;i=i+2){
			if(q%i==0)return false;
		}
		return true;
	}
}

int main(){
	int n;
	while(cin>>n){
		if(n+1>memo.size())memo.resize(n+1);
		int sum=0;
		for(int i=2;i<=n;i++){
			if(memo[i]==1){
				sum++;
				continue;
			}else if(memo[i]==-1){
				continue;
			}else if(isprime(i)){
				sum++;
				memo[i]=1;
			}else{
				memo[i]=-1;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

const int m=500000;
int prime[m];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<m; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<m; j+=i) prime[j]=0;
    }
    for(int i=1; i<m; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        if(n<2) cout<<"0\n";
        else cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}

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

int main(){

	int n, i, j, prmnum;
	bool prm = true;
	while(cin>>n){
		prmnum = 1;

		for( i=3;i<=n;i+=2 ){
			prm = true;

			for( j=3;j<=sqrt((double)i);j+=2 ){
				if( i%j == 0 ){
					prm = false;
					break;
				}
			}


			if(prm)prmnum++;
		}


		cout << prmnum << endl;
	}
	return 0;
}

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

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	int n;
	cin>>n;
	int count=0;
	for(int i=0;i<=n;i++){
		if(prime[i]==1){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

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

int main(){
	int n,s,a;
	
	while(cin >> n){
		a=1;
		for(int j=3;j<=n;j+=2){
			s=0;
			for(int i=3;i<j;i+=2){
				if(j%i==0){
					s=1;
					break;
				}
			}
			if(s==0){
				a++;
			}
		}
		cout << a << "\n";
	}
		
	
return 0;
}

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

using namespace std;


int main(){

	int i, j, k;
	int n;

	while(cin >> n){

		int count = 0;

		if(n>2){
			count ++;
			for(i=3 ; i<=n ; i+=2){
				for(j=3 ; j<=(int)sqrt(i) ; j+=2){
					k = i % j;
					if(k == 0) break;
				}
				if(j > (int)sqrt(i)) count ++;
			}
		}
		cout << count << endl;

	}


	return 0;
}

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

int main(){
  int n,i,j;
  while(cin >> n) {
    if(n==1){
      cout << 0 <<endl;
      continue;
    }
    int k = 0, a[n];
    a[0] = 2;
  
    for (i = 3; i <= n; i = i + 2) {
      for (j = 0; j <= k; j++) {
        if(i % a[j] == 0 ) break;
        if(i <= a[j] * a[j]) {
          k++;
          a[k] =i;
          break;
        }
        
      }
      if(j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    cout << k+1 << endl;
  }
  
  return 0;
}

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

int main()
{
	int n = 0, x = 0;
	int countdata[1000];
	while (cin >> n) {
		int count = 0;
		for (int a = 2; a <= n; a++) {
			if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a % 7 != 0) 
				count++;
			if (a == 2 || a == 3 || a == 5 || a == 7)
				count++;
		}
		countdata[x] = count;
		x++;
	}
	for (int a = 0; a < x; a++) {
		cout << countdata[a] << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int ma=1e7;
  vector<bool>sosu(ma,1);
  sosu[0]=sosu[1]=0;
  for(int i=4;i<ma;i+=2)sosu[i]=0;
  for(int i=3;i<ma;i+=2)
    for(int j=i*3;j<ma;j+=i*2)sosu[j]=0;
  int in;
  while(cin>>in){
    int co=0;
    loop(i,2,in+1)if(sosu[i])co++;
    cout<<co<<endl;
  }
}