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 <bits/stdc++.h>
 
using namespace std;

static const long MAX = 1000000L;
 
int main() {
    vector<long> prime;
    vector<long> dp;
    bool isPrime;
    long n, m;
 
    long i, len = sqrt(MAX) + 1;
    long j, lenJ;
    long k;
     
    prime.push_back(2);
    dp.push_back(0);
	dp.push_back(0);
	dp.push_back(1);

    for (i = 3; i <= len; i += 2) {
        isPrime = true;
        lenJ = prime.size();
        k = sqrt(i) + 1;
        for (j = 0; j < lenJ; j++) {
            if (k <= prime[j]) break;

            if (i % prime[j] == 0) {
                isPrime = false;

                break;
            }
	}

        if (isPrime) prime.push_back(i);
    }

    lenJ = prime.size();
     
    while (cin >> n) {
	if (n < dp.size()) {
		cout << dp[n] << endl;

		continue;
	}
         
	m = dp.size();
        for (i = m; i <= n; i += 2) {
            isPrime = true;

            k = sqrt(i) + 1;
            for (j = 0; j < lenJ; j++) {
                if (k <= prime[j]) break;

                if (i % prime[j] == 0) {
                    isPrime = false;

                    break;
                }
            }

            if (isPrime) {
		dp.push_back(dp.back() + 1);
		dp.push_back(dp.back());
	    } else {
		dp.push_back(dp.back());
		dp.push_back(dp.back());
	    }
        }
         
        cout << dp[n] << endl;
    }
 
    return 0;
}

C++: #include<iostream>
#include<math.h>
#include<fstream>
using namespace std;
int Test(int n);
int  main()
{
	fstream f;
	int n;
	f.open("taptin.txt", ios::in);
	f>>n;
	f.close();
	f.open("Ketqua.txt",ios::out);
	int t=0;
	if( n == 2)
	{
		t=1;
	}
	else
	{
		t =1;
		for(int i = 3 ; i <= n ; i= i+2)
		{
			if(i % 6 !=0)
			{
				if(Test(i)==1)
				{
					t= t+1;
				}
			}
		}
	}
	f<<t;
	f.close();
	return 0;
}
int Test(int n)
{
	for(int i = 2 ; i <= sqrt((float)n) ; i++)
	{
		if( n % i == 0)
			return 0;
	}
	return 1;
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	int i;
	int flag;
	int ans;
	
	while (scanf("%d", &n) != EOF){
		
		ans = 0;
		while (n >= 2){
			flag = 0;
			for (i = n - 1; i >= 2; i--){
				if (n % i == 0){
					flag = 1;
				}
			}
			
			if (flag == 0){
				ans++;
			}
			
			n--;
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include<stdio.h>
int num[999999];
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=999999;i++)
	num[i]=1;
for(int i=2;i<=999999;i+=2){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

C++: #include <cmath>
#include <cstdio>
 
inline bool fermat_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
    }
}
 
inline bool prime_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
            if ((n %= i) == 0) {
                return false;
            }
        }
    }
    return true;
}

unsigned short v[999999];

int main() {
    int n;
    v[3] = 2;
    while (~scanf("%d", &n)) {
        for (int i = 5; i <= n; i += 2) {
            if (v[i] > 0)
                continue;
 
            v[i] = v[i - 2] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", v[n % 2 == 0 ? n - 1 : n]);
    }
}

C++: #include <math.h>
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <string>

#define YES "YES"
#define NO "NO"
#define space ' '

using namespace std;

void init();
void func();

int main(void)
{
	
	func();

	return 0;
}


#define MAXIMUM 1000000
bool table[MAXIMUM];
int cnt[MAXIMUM];
bool not = true;
bool prime = false;

void init()
{
		table[0] = not;
	table[1] = not;
	for (int i = 2; i < MAXIMUM; i++)
	{
		if (table[i] == prime)
		{
			for (int j = i * 2; j < MAXIMUM; j += i)
			{
				table[j] = not;
			}
		}
	}
	for (int i = 1; i < MAXIMUM; i++)
	{
		if (table[i] == prime)
		{
			cnt[i] = cnt[i - 1] + 1;
		}
		else
		{
			cnt[i] = cnt[i - 1];
		}
	}

}

void func()
{
	
	int n;

	init();

	while (cin >> n, !cin.eof())
	{
		cout << cnt[n] << endl;
	}

}

C++: #include <iostream>

int main(void)
{
    int input;
    while(std::cin >> input){
        bool* table = new bool[input + 1]();
        for(int i=0; i <= input; ++i){
            if(i < 2){
                table[i] = true;
                continue;
            }
            if(table[i] == false){
                for(int j=2;i * j <= input;++j){
                    table[i * j] = true;
                }
            }
        }
        int count = 0;
        for(int i=0;i <= input;++i){
            if(table[i] == false){
                ++count;
            }
        }
        std::cout << count << std::endl;
        delete[] table;
    }
    return 0;
}

C++: #include <iostream>
#define N 100000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
    {
        cout << prime[n] << endl;
    }
    
    return 0;
}

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

int main(){
	int i, j, n, num = 0, count = 0;

	while(cin >> n){
		count = 0;
		for(i = 2; i <= n; i++){
			num = 0;
			for(j = 1; j <= i; j++){
				if(i % j == 0) num ++;
			}
			if(num == 2) count ++;
 		}
		cout << count << endl;
	}

	return 0;
}

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

bool IsPrime(int x) {
  return true;  /* ダミー: 全て素数と判定 */
}

int main(void){
   int count = 0, n;
   cin >> n; /* n個整数を読む */
   for(int i = 0; i < n; i++) {
       int p;
       cin >> p;
       if(IsPrime(p)) {
         bool IsPrime(int n) {
    for(int i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            return false;
        }
    }
    return true;
}


       }
   }
   cout << count << endl;
   return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX 1000000
/// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=666933#1
int main(){
    bool num[MAX];
    for(int i =2; i<MAX; i++) num[i] =true;

    for(int i=2; i*i < MAX; i++){
        for(int j=i; i*j <MAX;j++){
            num[i*j] =false;
        }
    }
    for(int n, count =0; cin >> n; cout << count <<endl, count=0){
        for(int i=2; i<=n; i++){
            if(num[i]) count++;
        }
    }
}