Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

C++: #include <cstdio>

int main(){
	int n;
	bool c[1000000]={true};
	int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = i;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<stdio.h>

bool p(int a){
	if(a==2)return true;
	if(a<2||a%2==0)return false;
	for(int i=3;i*i<=a;i+=2){
		if(a%i==0)return false;
	}
	return true;
}

int main(void){
	int n,cnt=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		if(p(i)){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

C++: #include <iostream>
#include <list>
#include <algorithm>
 
using namespace std;
 
int main() {
int n;
 
while(!cin.eof()) {
cin >> n;
list<int> search_list(n);
list<int> prime_number;
while(n!=1) {
search_list.push_front(n);
n--;
}
while(!search_list.empty()) {
int m = search_list.front();
prime_number.push_back(m);
search_list.pop_front();
list<int>::iterator it = search_list.begin();
while(it!=search_list.end()) {
if((*it % prime_number.front()) == 0){
it = search_list.erase(it);
continue;
}
it++;
}	
}
cout << prime_number.size()-1 << endl;
}
}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<'\n';}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;
tag:
m[i]=e;}}

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


bool prime[1000000];
int wei[1000000], sqrt_N = 1000;

int main()
{
  int N, i, j, k;

  for (i = 1; i <= 5; i += 4){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 4 * k * k + j * j) <= N; ++k){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 2; i <= 4; i += 2){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 3 * k * k + j * j) <= N; k += 2){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        if (N > 1000000)break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 3; i <= sqrt_N; i += 6){
    for (j = 1; j <= 2; ++j){
      for (k = j; k <= sqrt_N && (N = 4 * k * k + i * i) <= N; k += 3){
        if (N > 1000000) break;
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 5; i <= sqrt_N; ++i){
    if (prime[i]){
      for (j = i * i; j <= N; j += i * i){
        prime[j] = false;
      }
    }
  }
  prime[2] = prime[3] = true;

  for (i = 2; i < 1000000; ++i){
    wei[i] += wei[i - 1];
    if (prime[i]) wei[i]++;
  }

  while (~(scanf("%d", &N))) printf("%d\n", wei[N]);

  return 0;
}

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

bool isPrime(int a){
	int x = std::sqrt((double)a);
	for(;x>1;x-=2)
		if(a%x == 0)
			return false;
	return true;
}

int countPrime(int a){
	int x = a,ans = 1;
	if(x%2==0)
		x--;
	for(; x>1; x-=2)
		if(isPrime(x))
			ans++;
	return ans;
}

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#define REP0(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
using namespace std;
typedef long long ll;
const ll ccc=1000000;
bool prime[ccc+1];
vector<ll> pr;
int main(){
	ll iii,jjj;
	for(iii=0;iii<=ccc;iii++){
		prime[iii]=true;
	}
	prime[0]=false;
	prime[1]=false;
	for(iii=2;iii*iii<=ccc;iii++){
		if(prime[iii]){
			for(jjj=2*iii;jjj<=ccc;jjj+=iii){
				prime[jjj]=false;
			}
		}
	}
	for(iii=2;iii<=ccc;iii++){
		if(prime[iii]){
			pr.push_back(iii);
		}
	}
	int a;
	while(scanf("%d",&a)!=EOF) printf("%d\n",upper_bound(ALL(pr),a)-pr.begin());
	return 0;
}

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

bool primes[1000000];

void Sieve(){
    for(int i= 2; i < 1000000; i++){
        primes[i] = true;
    }
    primes[1] = false;    
    for(int i = 2; i < 1000; i++){
        if(primes[i] == true)
            for(int j=i; j*i < 1000000;j++){
                primes[j*i] = false;
            }
    }     
}
bool IsPrime(int x){
    return primes[x];
}

int main(void){
    Sieve();
    int n, c;
    while(cin >> n){
        c = 0;
        for(int i = 2; i <= n; i++){
        if(IsPrime(i)==true)
            c++;
        }
        cout << c << endl;
    }
    return 0;
}

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

using namespace std;

#define MAX_VALUE 1000000

int get_numprime( int num );

int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		int result = get_numprime( num );
		cout << result << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はカウント済み

	bool erat[MAX_VALUE] = {0};

	for( int i = 0 ; i < num+1 ; i++ )
	{
		erat[i] = true;
	}
	erat[0] = false; erat[1] = false;
	for( int i = 2 ; i <= num ; i++ )
	{
		if( erat[i] )
		{
			for( int j = i*2 ; j <= num ; j+=i )
			{
				erat[j] = false;
			}
		}
	}
	for( int i = 3 ; i <= num ; i+=2 )
	{
		if( erat[i] ) numprime++;
	}

	if( num == 1 ) numprime = 0;

	return numprime;
}

C++: #include <bitset>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    bitset<999999 + 1> b;
    auto t = b;
    t.set();
    t[0] = false;
    t[1] = false;
    int i = 0;
    while (true) {
        bool done = false;
        while (!t[i]) {
            ++i;
            if (i == t.size()) {
                done = true;
                break;
            }
        }
        if (done) {
            break;
        }

        b[i] = true;
        for (int j = i; j < t.size(); j += i) {
            t[j] = false;
        }
    }

    string s;
    while (getline(cin, s)) {
        int n = stoi(s);
        int count = 0;
        for (int j = 1; j <= n; ++j) {
            if (b[j]) {
                ++count;
            }
        }
        cout << count << endl;
    }
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    ll n;
    while(cin>>n){
        vector<bool> ip;
        if(ip.size()<n+1){
            ip.resize(n+1,true);
        }
        ip[0]=false;
        ip[1]=false;
        for(int i=2;i<=(n+1)/2;i++){
            for(int j=2;i*j<n+1;j++){
                ip[i*j]=false;
            }
        }
        ll ans=0;
        for(int i=0;i<n+1;i++){
            if(ip[i])ans++;
        }
        
        
        cout<<ans<<endl;
        
        
        
    }





return 0;
}