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 <cmath>
#include <iostream>

using namespace std;

bool prime_check(int n)
{
	if (n == 1)
	{
		return false;
	}
	else if (n == 2)
	{
		return true;
	}
	else
	{
		for (int i = 2; i <= sqrt(n); i++)
		{
			if (n % i == 0)
			{
				return false;
			}
		}
	}

	return true;
}

int main()
{
	// --- variable define --- //

	int n, c;


	// --- prime check ( 2 to 999 ) --- //

	bool isprime[1000];

	for (int i = 1; i < 1000; i++)
	{
		if (prime_check(i) == true)
		{
			isprime[i] = true;
		}
		else
		{
			isprime[i] = false;
		}
	}


	// --- main --- //

	while (cin >> n)
	{
		c = 0;

		for (int i = 2; i <= n; i++)
		{
			if (i <= 999)
			{
				if (isprime[i] = true)
				{
					c += 1;
				}
				else
				{
					c += 0;
				}
			}
			else
			{
				for (int j = 2; j <= sqrt(i); j++)
				{
					if (n % i == 0)
					{
						c += 0; goto Exit;
					}
				}

				c += 1;
			}
		Exit:;
		}

		cout << c << endl;
	}
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    vector<int> prime;
    prime.push_back(2);
    for (long long int i = 3; i < 999999; i++)
    {
        double temp = sqrt(i);
        for (int j = 0;; j++)
        {
            if (temp < prime[j])
            {
                prime.push_back(i);
                break;
            }
            if (i % prime[j] == 0)
            {
                break; //this is not prime
            }
        }
    }
    int n;
    int i;
    while (cin >> n)
    {
        for (i = 0; prime[i] <= n; i++);
        cout << i << endl;
    }
    return 0;
}

C++: #include<iostream>
int main(){
	for(int m,n,p;!(std::cin>>n).eof();){
		if(n<3)
			p=!(n-2);
		else for(m=3,p=1;m<=n;m+=2){
			p++;
			if(m<2)
				p--;
			else{
				for(int i=3;i*i<=m;i+=2)
					if(m%i==0){p--;break;}
			}
		}
		printf("%d\n",p);
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n){
    int i;
    if(n == 2)  return true;
    else if(n < 2 || n % 2 == 0)    return false;
    else{
        i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)  return false;
            i += 2;
        }
    }
    return true;
}
 
int main(void){
    int n, i, cnt;
    while(cin >> n){
        cnt = 0;
        for(i = 1; i <= n; i++){
            if(isPrime(i))  cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; continue;}
    for(int i=2; i<=n; i++) prime[i]=true;
    int ans=0;
    for(int i=2; i<=n; i++){
      if(prime[i]) {
        ans++;
        for(int j=2*i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}

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

int main(){
        int n;
        int d; //素数を入れるための添字
        bool count; //割りきれるかどうかの判定
        int number[400000]; //素数を入れておく
        number[0] = 2;
        
        
        while(cin >> n != 0){
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++)
                                if(i % number[j] == 0)
                                        count = false;
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                }
        cout << d+1 << endl;
        }
}

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

int main(){
	using namespace std;
	while(1){
		int n,i,j=2,count = 0;
		cin >> n;
		if (cin.eof() || n == 0) break;
		int prime[n+1];
		for(i=2;i<=n;i++) prime[i] = 1;
		for(i=2;i<=n;i++){
			if(prime[i] == 0) continue;
			else{
				for(j=2*i;j<=n;j++){
					if(j%i == 0) prime[j] = 0;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(prime[i] == 1) count += 1;
		}
		cout << count << endl;
	}
	return 0;
}

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

class prime{
	int sum;
	char p[MAX];
public:
	prime();
	int num(int n);
};

prime::prime(){
	p[0]=0;
	p[1]=0;
	p[2]=1;
	for(int i=3;i<MAX;i+=2)p[i]=1;
	for(int i=4;i<MAX;i+=2)p[i]=0;
	
	int c=3;
	while(c<1000){
		for(int i=c+2;i<MAX;i+=2){
			if(i%c==0)p[i]=0;
		}
		while(p[++c]==0);
	}
}

int prime::num(int n){
	sum=0;
	for(int i=0;i<=n;i++)sum+=p[i];
	return sum;
}

int main()
{
	int n;
	prime pr;
	while(cin >> n){
		cout << pr.num(n) << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int n;
bool is_prime[1000000];

int solve()
{
    int result = 0;
    for (int i = 0; i <= n; ++i)
    {
        is_prime[i] = true;
    }

    for (int i = 2; i <= n; ++i)
    {
        if (!is_prime[i])
        {
            continue;
        }
        ++result;
        for (int j = i * 2; j <= n; j += i)
        {
            is_prime[j] = false;
        }
    }
    return result;
}

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

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

int main()
{
	int i;

	for (i=0; i<999999; i++)
	{
		int num, j=2, count = 0;				
		scanf("%d", &num);

		int* check = (int*) malloc(sizeof(int)*num);			

		int k;
		for (k=0; k<num; k++)
		{
			check[num] = 0;
		}

		if (num == 2)
		{
			count++;
		}
		for (j=j; j<num; j++) 
		{
			if (check[j] == 1)
				continue;
			
			count++;

			int l;		
			for (l=2; l * j < num; l++)
			{				
				check[j * l] = 1;
			}			
		}
		printf("%d\n", count);
		free(check);
	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int prime[1000000];
int main(){
    int n,ans=0;
    for(int i=0;i<1000000;i++)
        prime[i]=1;
    prime[1]=0;
    prime[2]=1;
    for(int i=1;i<1001;i++){
        if(prime[i]==1){
            for(int j=i+1;j<1000000;j++){
                if(j%i==0)
                    prime[j]=0;
            }
        }
    }
    while(scanf("%d",&n)!=EOF){
        ans=0;
        for(int i=1;i<=n;i++){
            if(prime[i]==1)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}