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>
#include <math.h>
using namespace std;

int main(){
int n;
while(cin>>n){
	int m=0;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
}
return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MAX_N 11111111
using namespace std;
int prime[MAX_N];
bool is_prime[MAX_N];
int sieve(int n){
  int p = 0;
  for(int i=0;i<=n;i++)is_prime[i] = true; // 初期化
  is_prime[0] = is_prime[1] = false; // 例外処理
  for(int i=2;i<=n;i++){
    if(is_prime[i] == true){
      prime[p++] = i;
      for(int j=2*i;j<=n;j+=i)is_prime[j] = false;
    }
  }
  return p;
}
int main(){
  int n;
  while(cin >> n){
    cout << sieve( n ) << endl;
  }
}

C++: #include <stdio.h>

int main(){
	long sosuu[200000] = { 2 }, i, x, y = 1, z = 0;


	while(scanf("%d", &z)!=EOF){//入力した数以下の素数を表示

		for (i = 3; i < z + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++; }
			}
		}
		if (z < 2){ y = 0; }
	printf("%d\n", y);//最後に素数の合計数を表示

	for (i = 1; i < y; i++){
		sosuu[i] = 0;
	}y = 1; z = 0;
	}

	return 0;
}

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

int GetPrimeCount(int n)
{
	vector<bool> IsPrimeNumber(n+1, true);
	for(int i = 2; i <= n; i++){
		while(IsPrimeNumber[i] == false){
			i++;
		}
		for(int j = 2; i*j <= n; j++){
			IsPrimeNumber[i*j] = false;
		}
	}
	int Count = 0;
	for(int i = 2; i <= n; i++){
		if(IsPrimeNumber[i] == true){
			Count++;
		}
	}
	return Count;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(cin.eof() == true) break;
		cout << GetPrimeCount(n) << endl;
	}
	return 0;
}

C++: #include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j-1] = true;
		}
		}
	}
	for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

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

int main(){
	int n,w=1;
	cin >> n;
	for(int j=n;j>1;j--){
		for(int i=2;i<j;++i){
			if(j%i == 0){
				break;
			}
			if(i==j-1){
//				cout << j << endl;
				w++;
			}
		}
	}
	cout << w;	
	return 0;
}

C++: #include <iostream>
using namespace std;
 
bool IsPrime(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  int prime[1000000]={};
  for(int i=2;i<=1000000;i++){
      if(IsPrime(i)) prime[i]=prime[i-1]+1;
      else prime[i]=prime[i-1];
  }
   
  while(cin >> n) cout << prime[n]<< endl;

   
   return 0;
}

C++: #include<iostream>
#include<string.h>
int main(){int m=1,n=999999,o,c=n/2+1,d;bool*v=new bool[c];for(memset(v,1,c);m<499;m++)for(o=m*2+1,d=o*3;v[m]&&d<n+1;d+=o*2)v[d/2]=0;for(;!(std::cin>>n).eof();printf("%d\n",c))for(c=n-->1,m=1;m<n/2+1;)c+=v[m++];delete[]v;}

C++: #include <iostream>
#include <vector>
#define pb(a) push_back(a) 
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
 
int main() {
    int n = 1000000;
    vector<int> v;
    v.pb(2);
    for(int i=3;i<=n;i+=2) {
        bool add = true;
        rep(j,0,v.size()) {
            if(v[j] * v[j] > i) break;
            if(i % v[j] == 0) {
                add = false; 
                break;
            }
        }
        if(add) v.pb(i);
    }

    int m;
    while(cin >> m) {
        cout << upper_bound(v.begin(), v.end(), m) - v.begin() << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int prime[1000000];
int Prime_creat()
{
    int i,j;
    for(i=2;i<=1000000;i++)
    {
        if(prime[i])
        {
            for(j=i+i;j<=1000000;j+=i)
            prime[j]=0;
        }
    }
}
int main()
{
    int i,n,ans;
    memset(prime,1,sizeof(prime));//  1是素数 0不是素数
    Prime_creat();
    while(scanf("%d",&n)!=EOF)
    {
        ans=0;
        for(i=2;i<=n;i++)
        {
            if(prime[i])
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

int A[1000000];
int Eratosthenes(int n)
{
	int mama = 0;
	for (int i = 0; i < n; i++)
	{
		A[i] = 1;
	}
	for (int i = 2; i < sqrt(n); i++)
	{
		if (A[i])
		{
			for (int j = 0; i*(j + 2) < n; j++)
			{
				A[i*(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < n; i++)
	{
		if (A[i])
		{
			mama++;
		}
	}
	return mama;
}

int main()
{
	int n;

	while ((scanf("%d",&n))!= -1)
	{
		printf("%d\n", Eratosthenes(n+1));
	}
	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=i+1; j<=n;j++){
					if(j%i==0)
						v[j]=false;
				}
			}
		}
		for(int i=2;i<=n;i++){
			if(v[i]==true)
				cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include<stdio.h>

int main(){
  const int MAX_V = 1000000;
  int prime[MAX_V+1];
  int i, k, v;
  int ans;
  for(i = 2; i <= MAX_V; i++){
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++){
    if(prime[i]){
      for(k = 2 * i; k <= MAX_V; k += i){
        prime[k] = 0;
      }
    }
  }
  while(scanf("%d", &v) != EOF){
    int count = 0;
    for(k = 2; k <= v; k++){
      ans = prime[k];
      if(ans == 1){
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

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

/* {{{ */
#define PI(N) ((M_PI * (N)) / 180) //?§???????????????¢??????????????????
#define CL(N) (cout << (N) << endl)
#define DCT(N) (cout << "debug " << (N) << endl)
#define REP(i, N) for (int i = 0; i < (N); i++)
/* }}} */

bool f[1000001] = {false};

int main()
{
	for (int i = 2; i * i < 1000001; i++){
    	for (int j = i * i; j < 1000001; j += i){
            f[j] = true;
        }
    }

	int n;
    while (cin >> n){
        int c = 0;
        for (int i = 2; i <= n; i++){
            if (!f[i])c++;
        }
        CL(c);
    }

	return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
 
int main(){
int unti[100001] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
    if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt ;
    }
 
 
}