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 <cmath>
using namespace std;

int main() {
	
	int n;
	int count;
	int prime[999999];
	int max=0;
	
	
	while( cin >> n ){
		if(n > max){
		
			count = 1;
			prime[0] = 2;
			for(int i=3;i<=n;i+=2){
				int isPrime = true;
			
				for(int j=0;j<count;++j){
					if(i%prime[j] == 0){isPrime = false;break;}
				}
				if(isPrime){
					prime[count] = i;
					count++;
				}
			}
			max = n;
		}else{
			count = 0;
			for(int i=0;i<999999;++i){
				if(prime[i] > n)break;
				count++;
			}
		}
		cout << count << endl;
		
	}
	return 0;
}

C++: #include <cstdio>
const int N = 1000000;
int p[N],int pN[N];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)prime[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i] = c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

C++: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n;
	int count = 1;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
	}
	else if (n == 2) {
		cout << 1 << endl;
	}
	else {
		for (int t = 3; t <= n - 1; t += 2) {
			FOR(i, 1, t - 1) {
				if (t%i == 0) {
					break;
				}
				if (i == t - 1) {
					count++;
					break;
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

C++: 
//  test.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    long int j,s[1000000]={0},d=1,i,n,k;
    
    s[0]=s[1]=1;
    
    for(i=2;i<1000000;i++){
        if(s[i]==0){
            
            for(j=2;j*j<=i;j+=2){
                if(i%j==0)
                    break;
                if(j==2)
                    j=1;
            }
            
            
            if(j*j>i){
                d++;
                printf("%ld\n",i);
                if(i<1000){
                    for(k=2;k*i<1000000;k++){
                        s[k*i]=-1;
                    }
                }
            }
        }
        s[i] = d;
    }
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]-1);
    }
    
    
    return 0;
}

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

int f[1000001];
int main(){
    fill_n(f,f+1000001,1);
    f[0]=f[1]=0;
    
    for(int i=2;i<1000001;i++){
        f[i]+=f[i-1];
        if(!f[i])continue;
        for(int j=i+i;j<1000001;j+=i)f[j]=0;
    }
    
    int N;
    
    while(scanf("%d",&N),&N){
        printf("%d\n",f[N]);
    }
    
    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;
	int *prime = new int[n];
	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>
#include <cmath>

using namespace std;

bool N[999999];

int FindPrime(int n) {
  int ans = 0;
  for(int i = 1; i <= sqrt(n); i++) {
    if(N[i - 1]) {
      for(int j = 2; j <= n / i; j++) {
        N[i * j - 1] = false;
      }
    }
  }

  for(int i = 0; i < n; i++) {
    if(N[i]) {
      ans++;
    }
  }

  return ans;
}

int main() {
  int n;
  while(cin >> n) {
    for(int i = 1; i < n; i++) {
      N[i] = true;
    }

    int ans = FindPrime(n);

    cout << ans << endl;
  }

  return 0;
}

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


bool isPrime(int I)
{
	int b = sqrt (I*1.0) + 1;
	for(int i = 2; i < b; i ++){
		if(I % i == 0)
			return false;
	}
	return true;
}
void printPrime(int N)
{
	int total = 0;
	for(int i = 2; i <= N; i ++)
	{		
		if(isPrime(i) == true){
			total ++;
		}
	}
	cout<<total<<endl;
}


int main(){
	int n;
	while(cin>>n){
		printPrime(n);
	}
	
}

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

int main() {
	
	int n;
	int count;
	int *prime;
	
	
	while( cin >> n ){
		prime = new int[n];
		count = 1;
		
		prime[0] = 2;
		
		for(int i=3;i<=n;i+=2){
			int isPrime = true;
			
			for(int j=0;j<count;++j){
				if(i%prime[j] == 0){
					isPrime = false;
					break;
				}
			}
			
			if(isPrime){
				prime[count] = i;
				count++;
			}
		}
		
		cout << count << endl;
		
		delete[] prime;
	}
	
	return 0;
}

C++: #include<iostream>
#include <math.h>
#include <vector>
using namespace std;
int count=0,num=0;
int main()
{
	while(cin>>num)
	{
		count=0;
		vector<bool> a(num+1,true);
		for(int i=2;i<=sqrt(num);i++)
		{
			
			if(a[i]==true)
				for(int j=i*i;j<=num;j+=i)
				{
					
					a[j]=false;
				}
				
		}
		for(int  i=2;i<=num;i++)
		{
			cout<<a[i];
			if(a[i]==true)
				count++;
		
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int hako[1000100];
int main(){
	int n;
	while(cin >> n){
		int ret = 0;
		REP(i,1000100)hako[i] = 0;
		for(int i=2;i<=n;i++){
			if(hako[i] == 1)continue;
			ret++;
			for(int j=i;j <= n;j+=i){
				hako[j] = 1;
			}
		}
		cout << ret << endl;
	}
	return 0;
}

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

#define MAX 1000000



int main(void){

	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((double)MAX))+1;i++){
		if(p[i]){
			for(int j=i*2;j<=MAX;j=j+i){
				p[j]=false;
			}
		}
	}

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