Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[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;
	}
}