Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

C++: #include <iostream>
#include <math.h>
#define MAX 1000010
using namespace std;

int main(){
	int n;
	int *prime,i,j;
	prime = new int[80000];
	int *answer = new int[MAX];
	int count;
	bool flag;

	count = 0;
	answer[0] = 0;
	answer[1] = 0;
	answer[2] = 1;
	for(i = 3; i <= 1000000; i+=2){
		flag = true;
		for(j = 0; j < count; j++){
			if(i % prime[j] == 0){
				flag = false;
				break;
			}
			if(prime[j] * prime[j] > i) break;
		}
		if(flag == true){
			prime[count++] = i;
		}
		answer[i] = count;
		answer[i+1] = count;
	}
	while((cin >> n)!= NULL){
		cout << answer[n] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

int main() {
  const int MAX = 1000000;
  const int SQRT = (int)std::sqrt(MAX);
  bool isPrime[MAX];
  for (int i = 0; i < MAX; i++) {
    isPrime[i] = true;
  }
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < SQRT; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (std::cin >> n) {
    int cnt = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) cnt++;
    }
    std::cout << cnt << std::endl;
  }
}

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

bool prime[1000001];

void era(){
	for(int i=0;i<1000000;i++)prime[i]=1;
	prime[0]=0;
	prime[1]=0;
	for(int i=0;i<1000000;i++){
		if(prime[i]==true){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=0;
			}
		}
	}
}

int main(){
	era();
	int n,ans;
	while(cin>>n){
		ans=0;
		for(int i=0;i<n;i++){
			if(prime[i]==1)ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


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

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

int is_prime(int n){
    int i;
    int flag = 0;
    for(i=2; i<n; i++){
        if(n%i==0) { flag=1; break; }
    }
    return (flag==1)?0:1;
}


int main(){
	int i, j, n, num = 0, count = 0;
	
	while(1){
		cin >> n;
		if(cin.eof()) break;
		count = 0;
		for(i = 1; i <= n; i++){
			if(is_prime(i) == 1 && i != 1) count ++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	int premaxin=1;


	for(i=0;i<100000;i++){
		c[i]=1;
		data[i]=0;
	}
	c[0]=c[1]=0;

	while(scanf("%d",&n)!=EOF){

		if(premaxin<n){
			for(i=0;i<=n;i++){
				if(c[i]==1){
					if(premaxin>i){
						j=premaxin;
					}else{
						j=i+1;
					}
					for(;j<=n;j++){
						if(j%i==0){
							c[j]=0;
						}
					}
				}
			}

			count=data[premaxin];
			for(i=premaxin+1;i<=n;i++){

				if(c[i]==1){
					count++;
				}
				data[i]=count;
			}
		}

		printf("%d\n",data[n]);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int get_numprime( int num );

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 = 1; // 2はすでにカウント

	for( int i = 3 ; i <= num ; i+=2 )
	{
		int flag = 1;
		for( int j = 2 ; j <= i/2 ; j++ )
		{
			if( i%j == 0 )
			{
				flag = 0;
				break;
			}
		}
		if( flag == 1 ) numprime++;
	}

	return numprime;
}

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

using namespace std;

const int N = 1e6;
const int SQRTN = ceil(sqrt((double) N));
bool isPrime[N + 1];
int prefixsum[N + 1];

// Eratosthenes筛选法
void esieve(void)
{
    memset(isPrime, true, sizeof(isPrime));

    isPrime[0] = isPrime[1] = false;
    for(int i=2; i<=SQRTN; i++) {
        if(isPrime[i]) {
            for(int j=i*i; j<=N; j+=i)  //筛选
                isPrime[j] = false;
        }
    }
}

void maketable()
{
    prefixsum[0] = 0;
    for(int i = 1; i <= N; i++)
        prefixsum[i] = isPrime[i] ? prefixsum[i - 1] + 1 : prefixsum[i - 1];
}

int main()
{
    esieve();

    maketable();

    int n;
    while(~scanf("%d", &n))
        printf("%d\n", prefixsum[n]);

    return 0;
}

C++: #include<cstdio>
using namespace std;
const int N = 1000000;
int IsPrime[N];
int main(){

  IsPrime[0] = 1;
  IsPrime[1] = 1;
  for(int i=2; i<=N;i++){
    if(IsPrime[i]==0){
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = 1;
      }
  }
  int max;
  while(~scanf("%d",&max)){
    int count=0;
    for(int i=1; i<max+1; i++)
      if(IsPrime[i]==0) count++;
    printf("%d\n",count);
  }
}

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

int main()
{
	int count=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<0<<endl;
		}

		else{
		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				count++;
		}
		cout<<count<<endl;
		count=1;}
	}
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

bool t[1000000];

int main(){
	memset(t,1,sizeof(t));
	t[0] = t[1] = false;
	for(int i = 2; i < 1000; i++){
		if(t[i])
			for(int j = 2 * i; j < 1000000; j += i){
				t[j] = false;
			}
	}

	int n;
	while(cin>>n){
		int ans = 0;
		for (int i = 0; i <= n; i++)
		{
			ans += t[i];
		}
		cout << ans << endl;
	}

	return 0;
}

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

int status[1000000];

int main()
{
	int t, sq, i, j, count=0;

	scanf("%d",&t);

	sq=sqrt(t);

	for(i=0;i<=t;i+=2)
	{
	    status[i]=1;
	}
    status[1]=1;
    status[2]=0;
	for(i=3;i<=sq;i+=2)
	{
	    if(status[i]==0)
	    {
	        for(j=i*i;j<=t;j+=i)
    	    {
    	        status[j]=1;
    	    }
	    }
	}

	for(i=0;i<=t;i++)
	{
	    if(status[i]==0)
	    {
            count++;
	    }
	}

    printf("%d\n",count);

	return 0;
}