Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include<iostream>

using namespace std;

int main(){

int data[1000000];


 for(int i = 0; i < 1000000; i++) data[i] = 1;

 for(int i = 2; i*i < 1000000; i++){
   if(data[i] == 1){
     for(int j = i*2; j < 1000000; j+=i) data[j] = 0;
   }
 }
 int in;
 
 while(cin >> in){
   
   int sum = 0;
   for(int i = 2; i <= in; i++){
     if(data[i] == 1) sum++;
   }
   
   cout << sum <<endl;
 }
 return 0;
}

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

bool isPrime(int);

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

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

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)

bool prime[1000000];
int cou[1000000]={0};

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

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

int main(){
  
  int n,cnt = 0;

  while(cin >> n){
    int num[n] ={0};
    for(int i = 2; i  <= n; i++){
      if(num[i] == 0){
        for(int j = 1; j <(n/i); j++){
          num[i+(j*i)] = 1;
        }
        cnt++;
      }
    }
  cout << cnt << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<double, int>;

int main() {
    vector<bool> is_prime(1000000, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<is_prime.size(); ++i) {
        if(is_prime[i]) {
            prime.push_back(i);
            for(int j=i+i; j<is_prime.size(); j+=i) {
                is_prime[j] = false;
            }
        }
    }
    int n;
    while(cin >> n) {
        cout << upper_bound(prime.begin(), prime.end(), n) - prime.begin() << endl;
    }
}

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

int main()
{
 bool prime[1000000];
 for(int i=0; i<1000000; i++) prime[i] = true;

 prime[0] = prime[1] = false;
 for(int i=0; i<1000000; i++)
  if(prime[i]){
   for(int j=i+i; j<1000000; j += i)
    prime[j] = false;
  }

 int n;
 while(cin >> n){
  int c = 0;
  for(int i=0; i<=n; i++)
   if(prime[i]) c++;
  
  cout << c << '\n';
 }

 return 0;
}

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

bool t[1000000] = {};

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

int main() {
  int n, i, r;
  n = 999999;

  for (i = 0; i < n; i++) {
    t[i] = is_prime(i);
  }

  while (cin >> n) {
    r = 0;
    for (i = 2; i <= n; i++) {
      if (t[i]) {
        r++;
      }
    }
    cout << r << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	if(x == 2){
 		return 1;
	}
	i = 3;
	while( i <= sqrt(x) ){
		if(x%i==0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			if(isprime(i)){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

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

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

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

using namespace std;
#define MAX_N 999999
int n;//n以下の素数がいくつあるか出力する
int ans;//素数の数
int prime[MAX_N];//prime[i]が1ならば素数i+1は素数
int main(){
  while(scanf("%d",&n) != EOF){
    ans = 0;
    for(int i= 0;i < n;i++){
      prime[i]= 1;
    }
    prime[0] = 0;//1は素数でないので
    for(int i = 1;i <sqrt(n);i++){
      if(prime[i] == 1)
	for(int j =(i+1);(i+1)*j <=n;j++){
	  prime[(i+1)*j-1] = 0;
	}
  }
    for(int i = 0;i < n;i++){
      if(prime[i] == 1)
	ans++;
    }
      printf("%d\n",ans);
  }
  return 0;
}

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

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

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


int solve(int b){
    int m = 0;
    int x[1000000];
    if(b == 1){
        return 0;
    }else if(b==2){
        return 1;
    }
    x[m++] = 2;
    for(int i=3;i<=b;i+=2){
        bool a = true;
        for(int j=0;j<m;j++){
            if(i%x[j]==0){
                a = false;
                break;
            }
        }
        if(a){
            x[m++] = i;
        }
    }
    return m;
}

int main(){
    int n;
    while((cin>>n)){
        cout << solve(n) << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#define long long long
const int N = 100005;
bool np[N];
void eratos() {
    np[0]=np[1]=true;
    for (int i=2; i*i<N; i++) if (!np[i])
        for (int j=i*i; j<N; j+=i) np[j]=true;
}
main()
{
	eratos();
	long n,d=0;
do
{
    d=0;
	cin>>n;
	for(long i=0;i<=n;i++)
	if(np[i]==false)
	d++;
	cout<<d<<endl;
}while(1);
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;
      
      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]==true){
        for(int j = i;i<MAX;j*j)
        v[i]=false;
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int s[80000],m[10000000],i,j,n=0;
int main() {
	for (i=2; i<1000000 ; i++) {
		if (m[i]==0) {
			s[n++]=i;
			for (j=i; j<10000000; j+=i) m[j]=1;
		}
	}
	while(cin >> i) {
		for (j=0;s[j]<=i && j<n;j++) ;
		cout << j << endl;
	}
return 0;
}

C++: #include<stdio.h>
#define max 1000001;

int main(void)
{
	int *d, f1, f2, n, cnt;
	d = new int [max];
	for(f1 = 0; f1 < max; f1++)
	{
		d[f1] = 1;
	}
	for(f1 = 2; f1 *f1 < max; f1++)
	{
		if(d[f1] == 1)
		{
			for(f2 = 2 * f1; f2 < max; f2 += f1)
			{
				d[f2] = 0;
			}
		}
	}
	while (scanf("%d",&n) != EOF)
	{
		cnt=  0;
		for(f1 = 2; f1 >= n; f1++)
		{
			if(d[f1] == 1)
				cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int a[1000500];
int main(){
	for(int i=2;i*i<1000500;i++){
		for(int j=i*2;j<1000500;j+=i){
			a[j]=1;
		}
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=2;i<=b;i++){
			if(a[i]==0) c++;
		}
		cout<<c<<endl;
	}
}