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>
#define MAX 1000000

using namespace std;

bool prime[MAX+1];
int T[MAX];

void eratos( int n ){
    for ( int i = 0; i < n; i++ ) prime[i] = false;
    for ( int i = 3; i <= n; i += 2 ) prime[i] = true;
    prime[2] = true;
    for ( int i = 3, limit = (int)sqrt(n); i <= limit; i += 2 ) {
	if ( !prime[i] ) continue;
	for ( int j = i * i, k = i * 2; j <= n; j += k ) prime[j] = false;
    }
}

void initialize(){
    eratos( MAX );
    for ( int i = 0; i < MAX; i++ ){
	T[i] = T[i - 1];
	if ( prime[i] ) T[i]++;
    }
}

main(){
    initialize();
    int n;
    while ( cin >> n ) cout << T[n] << endl;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
int* table =  new int[1000000];
while(~scanf("%d",&n)){

fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i<=n;i++){
if(table[i]) {
for(int j=i+i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	
	char p[1000000];
	for(int i=2;i<1000000;i++)p[i]=1;
	for(int i=2;i<1000;i++){
		if(p[i]==0)continue;
		for(int j=i+1;j<1000000;j++){
			if(p[j]==0)continue;
			if(j%i==0)p[j]=0;
		}
	}
	
	int n,c;
	while(scanf("%d",&n)!=EOF){
		c=0;
		for(int i=0;i<=n;i++)if(p[i]==1)c++;
		cout<<c<<endl;
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
// have you mooed today?
bool isprime(int& num)
{
    static int c;
    static int max;
    max = sqrt(num) + 2;
    if(num == 2) return true;

    for(c=2; c < max; c++)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans = 0;
    int buff;
    while(cin >> buff);
    {
        for(int d =2; d <= buff; d++)
        {
            if(isprime(d)) ans++;
        }
        cout << ans << endl;
        ans  = 0;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[1000005] = {0,};
vector<int> primeVec;
void genPrime(){
	for (int i=2;i<=1000000;i++){
		if (a[i]) continue;
		else{
			a[i] = 2;
			primeVec.push_back(i);
			if (i >= 1000) continue;
			for (int j=i*i;j<=1000000;j+=i) a[j] = 1;
		}
	}
}
int main(){
	genPrime();
	int n;
	while(cin >> n)
		cout << upper_bound(primeVec.begin(), primeVec.end(), n) - primeVec.begin() << endl;
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>

#define int64 long long int

using namespace std;

int main()
{
	int n;
	bool p[1000000] = {0};

	for(int i=2; i<=1000; i++){
		if(!p[i])
			for(int j=2*i; j<1000000; j+=i) p[j] = true;
	}

	while(cin >> n){
		int count = 0;
		for(int i=2; i<=n; i++)
			if(!p[i]) count++;
		cout << count << '\n';
	}

	return 0;
}

C++: #include<iostream>

bool isPrime(int i){
	for (int j = 2; j*j <= i; j += 2){
		if (i%j == 0)return false;
		if (j == 2)--j;
	}
	return true;
}

int main(){
	int n;
	int count = 0;
	while (std::cin >> n){
		count = 0;
		for (int i = 2; i <= n; ++i){
			if (i == 2)++count;
			else if (isPrime(i))++count;
		}
		std::cout << count << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,x,i;
	while((scanf("%d",&a))!=EOF){
		x=0;
		for(i=2;i<a+1;i++){
			if(i%2!=0&&i%3!=0&&i%5!=0&&i%7!=0){
				x++;
			}
			else if(i==2||i==3||i==5||i==7){
				x++;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

C++: #include <stdio.h>

int main(void){
int n;
while(scanf("%d",&n)!=EOF){
int count=0;
for(int m=2;m<=n;m++){
bool check=true;
for(int i=2;i<m;i++){
if(i!=m && m%i==0){
check=false;
}
}
if(check==true){
count++;
}
}
printf("%d\n",count);
}
return 0;
}

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


int main() {

	int judge[1000000];
	for(int k=0;k<1000000;k++)judge[k]=1;
	int n;
	
	while(cin>>n){
		int sum = 1;
		for(int i=3;i<n+1;i+=2){
			if (judge[i]==1){
				sum++;
				for(int j=2;j<=n/i;j++)
					judge[i*j] = 0;
			}	
		}
		
		cout << sum <<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool prime(int x){
  for(int i=2;i<x;i++){
    if(x%i==0)return false;
  }
  return true;
}

int main(){
  int n;
  while(cin>>n){
    int sum=0;
    for(int i=2;i<=n;i++){
      if(prime(i))sum++;
    }
    cout<<sum<<endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000005]={0};
	for(int i=2;i<1000000;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		if(flag){
		sosu[i]=1;
		}
	}
	while(cin>>n){
	ans=0,cnt=0;
	for(int i=2;i<=n;i++){
		if(sosu[i]==1){
		ans++;
		}
	}
	cout<<ans<<endl;
	}
    return 0;
}

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

using namespace std;

int prime(int a){
    int sqt = sqrt(a);
    int *array = new int[a+1];
    array[1] = 1;
    array[2] = 0;
    array[3] = 0;
    if(a >= 4){
        for(int i = 2; i <= sqt; i++){
            for(int j = 2; j*i <= a; j++){
                array[i*j] = 1;
            }
        }
    }
    int count = 0;
    for(int i = 1; i <= a; i++){
        if(array[i] == 0) count++;
    }
    return count;
}

int main(){
    int n;
    while(cin >> n){
        cout << prime(n) << endl;
    }
}

C++: #include<stdio.h>  
#include<math.h>
  
int main(void)
{  
	//入力変数
    int n = 0;  
	//素数判定flag
    bool isPrime = true;
	//素数カウント変数
    int count = 0;  
	//素数格納配列
    int prime[100000];  
	//ループの最高回数
	int imax = 0;
  
    while(scanf("%d", &n) != EOF) 
	{  
        count = 0;  
  
		//2は特別扱い
		if (n >= 2)
		{
	        prime[0] = 2;  
			count++;
		}

		//2の倍数はいらない
        for(int j = 3; j <= n; j += 2) 
		{  
			//素数かそうでないかの判断をするflag
			isPrime = true;  
  
			//平方根を求める
			imax = sqrt(double(j));

			//ここでエラトステネスのふるいで使った平方根の考え方を利用
            for(int i = 0; prime[i] <= imax; i++)
			{  
                if(j % prime[i] == 0)
				{  
                    isPrime = false;  
                    break;  
				}  
			}

			//素数だった場合
		    if(isPrime == true) 
			{  
				prime[count++] = j;  
			}  
		}  
  
		printf("%d\n", count);  
  
    }  
  
    return 0;  
}

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

int main() {
	int n,ans=0,prime[1000000];
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;++i){ prime[i]=1; }
	for(int i=2;i<1000000;++i){
		if(prime[i]==1) {
			++prime[i];
			if(i<1000) for(int j=i*i;j<1000000;j+=i) prime[j]=0;
		}
	}
	while(scanf("%d",&n) != EOF) { printf("%d\n",prime[n]); }
	return 0;
}

C++: #include<iostream>

using namespace std;

int get_numprime( int num );
bool prime( int n );


int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		cout << get_numprime( num ) << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 0;

	for( int i = 2 ; i <= num ; i++ )
	{
		if( prime(i) ) numprime++;
	}

	return numprime;
}

bool prime( int n )
{
	for( int i = 2 ; i <= n/2 ; i++ )
	{
		if( n%i == 0 )
		{
			return false;
		}
	}
	return true;
}