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 <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n;
bool is_prime[1000000];
int prime[1000000];

int main(int argc, char const* argv[])
{
	fill(is_prime, is_prime+1000000, true);
	is_prime[0] = false;
	is_prime[1] = false;
	int res = 0;
	for(int i = 2; i < 1000000; i++){
			if(is_prime[i]){
					res++;
					for(int j = 2; j * i < 1000000; j++){
							is_prime[j * i] = false;
					}
			}
			prime[i] = res;
	}
	while(cin >> n){
			cout << prime[n] << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;
int main() {
  long n;
  vector<long> primes;
  primes.push_back(2);
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 3; i <= n; i += 2) {
      bool prime = true;
      for (unsigned int j = 0; j < primes.size() && primes[j] * primes[j] <= n; j++)
        if (i % primes[j] == 0) {
          prime = false;
          break;
        }
      if(prime && find(primes.begin(), primes.end(), i) == primes.end()) {
        primes.push_back(i);
      }
    }
    int x = 0;
    for (long& e: primes)
      if (e <= n) x++;
    cout << x << endl;
  }
}

C++: #include<Upstream>
#include<cstdio>
#include<cstring>
using namespace std;

Int pn[1000002];

int main(){
int n, Count;
con.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,n);
pn[0]=pn[1]=1;
for(int i=0;i<=n;i++) if(!pn[i]) for(int j=0;i*j<=n;j++) pn[i*j]=1;
Count=count(pn,pn+n,0);
count<<Count<<endl;
}
return 0;
}

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<ll> v;
        for(int i=0;i<n+1;i++){
            v.push_back(i);
        }
        ll b=v[v.size()-1];
        for(int i=2;i<=n;i++){
            ll j=2;
            while(i*j<=b){
                v[i*j]=0;
                j++;
            }
        }
        ll ans=0;
        for(int i=0;i<v.size();i++){
           // cout<<v[i]<<endl;
            if(v[i]!=0)ans++;
        }
        cout<<ans-1<<endl;
    }
    
    
    return 0;
}*/
int main(){
    
    ll n;
    while(cin>>n){
       /* ll ans=0;
        for(int i=3;i<=n;i+=2){
            int flag=0;
        for(int j=3;j<=sqrt(i);j+=2){
            if(i%j==0){
                flag=1;
                break;
            }
        }
            if(flag==0){
                ans++;
            }
    }
        cout<<ans+1<<endl;*/
        
        vector<bool> IsPrime;
        if(n+1>IsPrime.size()){
            IsPrime.resize(n+1,true);
        }
        IsPrime[0]=false;
        IsPrime[1]=false;
        for(int i=2;i<=sqrt(n);i++){
            if(IsPrime[i]){
                for(ll j=2;i*j<=n;++j){
                    IsPrime[i*j]=false;
                }
        }
        
        }
        ll ans=0;
        for(int i=0;i<IsPrime.size();i++){
            if(IsPrime[i])ans++;
        }
        cout<<ans<<endl;
        }
    
    return 0;
}

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

int main(){
	int N;
	int r;
	int j;
	int count;
	list<int> counter;
	
	while(!(cin>>N).eof()){
		if(N==2 ){
			counter.push_back(1);
		}
		else if(N==3){
			counter.push_back(2);
		}
		else {
			count=0;
			for(int i=3; i<=N; i+=2){
				j=3;
				do{
					r = i%j;
					if(j!=3 && r == 0) break;
					j+=2;
				}while(j<=(i/2)+1);
				if(i!=3 && r==0) continue;
				count++;
				
			}
			counter.push_back(count);
		}	
	}
	list<int>::iterator it = counter.begin();
	while(it != counter.end()){
		cout << *it << endl;
		it++;
	}
	return 0;
}

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

//素数かどうか判定する関数
bool judge( int x )
{

    for( int i = 2; i <= x - 1; i++ )       //ex与えられた数が10なら
    {                                       //2~9までの数で割り切れたら、素数ではない。
        if( x % i == 0)
            return false;
    }

    return true;
}

int main()
{
    int n;

    while( cin >> n )                           //2が素数であることを予め考慮
    {
        int count = 1;                          //countは素数の数なので、1

        if( n <= 1 )                            //nが1以下なら素数の数は0
        {
            count = 0;
        }

        for( int i = 3; i <= n; i += 2 )        //3以上の自然数について、奇数のみ素数判定を行う
        {
            if( judge(i) )
                count++;
        }

        cout << count << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7+1;
int prime[maxn];
bool is_prime[maxn];

int sieve(int n) {
    int p = 0;
    for(int i = 1; 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]) {
            prime[p++] = i;
            for(int j = i+i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return p;
}

int main() {
    int n;
    while(scanf("%d", &n) != EOF) {
        printf("%d\n", sieve(n));
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define debug(n) cout<<"# "<<#n<<": "<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n;){
		deque<bool> is_prime(n+1,true);
		is_prime[0]=is_prime[1]=false;
		repi(i,2,is_prime.size()){
			if(is_prime[i])
				for(int j=i+i;j<is_prime.size();j+=i)
					is_prime[j]=false;
		}
		cout<<count(allof(is_prime),true)<<endl;
	}
	
	return 0;
}

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

bool is_prime[1000000];
int prime[1000000];

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