Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[100000];
    int n;
    a[0]=2;
    int k=1;
while(cin>>n){
    for(int i=3;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<k<<endl;
    k=1;
 }
}

C++: #include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;
int N;
int primes[1000000];

void prime() {
    fill(primes, primes + 1000000, 1);
    for (int i = 2; i <= 999999; i++) {
        if (primes[i]) {
            for (int j = i + i; j <= 999999; j += i)
                primes[j] = 0;
        }
    }
}

int main() {
    prime();
    while (~scanf("%d", &N)) {
        int ans = 0;
        for (int i = 2; i <= N; ++i)
            ans += primes[i];
        printf("%d\n", ans);
    }
    return 0;
}

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

const int maxn = 1e7+10;

int prime[maxn];
bool is_prime[maxn];

int sieve(const int& n){
	int p = 0;
	fill(is_prime,is_prime+n+1,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=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 <iostream>
using namespace std;

long mygcd(long a, long b)
{
    if (b == 0) return a;
    if (a < b) return mygcd(b,a);
    return mygcd(a-b,b);
}

int main(void)
{
    long num, length, prime[1000];

    while(cin >> num)
    {
        length = 0;
        int count = 0;
        for (int n = 2; n <= num; n++)
        {
            // judge whether n is prime or not
            bool isPrime = true;
            for(int i=0; i < length-1; i++)
            {
                if (!(n % prime[i]))
                {
                    isPrime = false;
                    break;
                }
            }
            // regist n as prime number
            if (isPrime)
            {
                prime[length] = n;
                length++;
            }
        }
        cout << length << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>

const int N = 1000009;
int dp[N];
int isprime[N];

int main()
{
    dp[1] = 0;
    for(int i=2;i<N;i++)
    {
        if(!isprime[i])
            for(int j=2*i;j<N;j+=i)
                isprime[j] = 1;
        dp[i] = dp[i-1] + isprime[i];
    }

    int y;
    while(~scanf("%d",&y))
        printf("%d\n",dp[y]);
    return 0;
}

C++: /*
 * fudq.cpp
 *
 *  Created on: 2015-10-24
 *      Author: bjfudq
 */
#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")


#define MEM(a) (memset((a),0,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define fr(a) for(int i=0;i<(a);i++)
#define sf(a) scanf("%d",&(a))
#define sf64(a) scanf("%I64d",&(a))
#define sff(a) scanf("%lf",&(a))
#define sfs(a) scanf("%s",(a))
#define sf2(a,b) scanf("%d%d",&(a),&(b))
#define sf3(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2s(a,b) scanf("%s%s",(a),(b))
#define sf2f(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3f(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pf(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a))
#define pf64(a) printf("%I64d\n",(a))
#define pff(a) printf("%lf\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s%s\n",(a),(b));
#define pf2f(a,b) printf("%lf %lf\n",(a),(b))
#define pf264(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfk printf(" ")
#define LL long long

const int N=100010;
const int M=1000010;
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const int dir4[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int dir8[8][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
const double eps=1e-12;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
/*************************/

int tot,prime[N+10],f[N+10];

void Getprime()
{
	memset(f,0,sizeof(f));
	tot=0;
	for(int i=2;i<=N;i++)
	{
		if(f[i] == 0)
			prime[tot++]=f[i]=i;
		for(int j=0;j<tot && prime[j]<=f[i] && i*prime[j]<=N;j++)
			f[i*prime[j]]=prime[j];
	}
}



int main(){
    Getprime();
    int n;
    while(sf(n)!=EOF){
    	int p=lower_bound(prime,prime+tot,n)-prime;
    	if(prime[p] != n) p--;
    	pf(p+1);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=10000010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int prime[MAX];		
void erast(){
	prime[0]=0;prime[1]=0;
	for(int i=2;i<MAX;i++){
   		prime[i]=1;
	}
	for(int i=2;i<=MAX/2;i++){
    	if(prime[i]==1){
        	for(int j=i+i;j<=MAX;j+=i){
            	prime[j]=0;
        	}
    	}
	}
}
int main(){
	int n;
	erast();
	while(cin>>n){
		int ans=0;
		for(int i=1;i<=n;i++){
			if(prime[i]){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int prime(int a){

int i,p;

if(a == 2) return 1;
if(a % 2 == 0) return 0;
p = sqrt(a);
for(i=3;i<=p;i+=2){
if(a%i == 0) return 0;
}
return 1;
}

int main(void){

	int a,i,sum;


	while(scanf("%d",&a) != EOF){
		sum = 0;
		for(i=1;i<=a;i++){
		sum += prime(i);
		}
		printf("%d\n",sum-1);
		}

}

C++: #include <stdio.h>
#include <stdbool.h>

int main(void)
{
  bool notPrime[1000000];
  int primeNum[1000000];
  int i,j;
  for(i=2; i<1000000; ++i){
    if(!notPrime[i]){
      primeNum[i] = primeNum[i-1]+1;
      if(i<1000){
        for(j=i*2; j<1000000; j+=i){
          notPrime[j] = true;
        }
      }
    }else{
      primeNum[i] = primeNum[i-1];
    }
  }
        
  int n;
  while(scanf("%d", &n) != EOF){
    printf("%d\n", primeNum[n]);
  }

  return 0;
}

C++: 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		vector<int> sos;
		sos.emplace_back(2);
		int s = 1;
		for (int j = 2; j <= n; j++) {
			for (int i = 0; i < sos.size(); i++) {
				if (j%sos[i] == 0) {
					break;
				}
				if (sos[i]>sqrt(j)) {
					sos.emplace_back(j);
					s++;
					break;
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}