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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

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

//素数かどうか判定する関数
bool judge( int x )
{
    int count = 0;

    for( int i = 1; i <= x; i += 2 )
    {
        if( x % i == 0)
            count++;
    }

    if( count == 2 )
        return true;
    else
        return false;
}

int main()
{
    int n;

    while( cin >> n )                           //2が素数であることを予め考慮
    {
        int count = 1;                          //coutは素数の数なので、1

        if( n <= 1 )                            //nが1以下なら素数の数は0
        {
            count = 0;
        }

        for( int i = 3; i <= n; i += 2 )        //3以上の自然数について、奇数のみ素数判定を行う
        {
            if( judge(i) )
                count++;
        }

        cout << count << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	int n;
	while (scanf_s("%d", &n) != EOF) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

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

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

int main() {
  int n;
  while(cin >> n) {
    int num = 0;
    for(int i = 2; i <= n; ++i) num += isPrime(i);
    cout << num << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#define M 1000000

using namespace std;

int main() {

	int c, n;
	bool x[M];

	for(int i=2; i<=M; i++) {
		x[i]=false;
	}
	for(int i=2; i<1000; i++) {
		if(x[i])
			continue;
		for(int j=i*2; j<M; j+=i) {
			if(!x[j])
				x[j]=true;
		}
	}

	while(scanf("%d", &n)!=EOF) {
		c=0;
		for(int i=2; i<=n; i++) {
			if(!x[i])
				c++;
		}
		cout << c << endl;
	}
	

	return 0;

}

C++: #include<iostream>
using namespace std;
int main()
{
    int i=2, j=2, n;
    
    cout<<"Enter a number to print Prime Number: ";
    cin>>n;
    
    cout<<i<<" ";
    
    for(i=2; i<=n; i++)
             for(j=2; j<i; j++)
             {
                      if(i%j == 0)
                      break;
                      else if(i==j+1)
                      cout<<i<<" ";
             }
             
    cout<<endl;
    
    system("pause");
    return 0;
}

C++: #include <iostream>

#define MAX_SIZE 1000000

using namespace std;

void sieve(bool *a) {
    a[0] = a[1] = true;
    
    for(int i = 2;i < MAX_SIZE;i++) {
        if(!a[i]) {
            for(int j = 2;(i * j) < MAX_SIZE;j++) {
                a[i * j] = true;
            }
        }
    }
}

int main() {
    bool not_prime[MAX_SIZE] = { false };
    
    sieve(not_prime);
    
    int n, cnt;
    
    while(cin >> n) {
        cnt = 0;
        
        for(int i = 0;i <= n;i++) {
            if(!not_prime[i]) {
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }
    
    return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


int f(int a){
	if(a==1) return 0;
	for(int i=2;i<=sqrt((double)a);i++){
		if(!(a%i)){
			return 0;
		}
	}
	return 1;
}
bool solve(){
	int n;
	while(cin>>n){
		int cnt=0;
		for(int j=2;j<=n;j++){
			cnt += f(j);
		}	
		cout<< cnt<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

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

int main(){
   int i,j,n,flag=0,x=1;
   int sosu[999];
   sosu[0] = 2;
   cin>>n;
   for(i=3;i<=n;i++){
      flag = 0;
      
      for(j=0;j<x;j++){
         if(i%sosu[j] == 0){
            flag++;
            break;
         }
      }
      if(flag == 0){
         sosu[x] = i;
         x++;
      }
   }
   printf("%d\n",x);
   return 0;
}

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

typedef unsigned int Int;

Int sqrt_prm(const Int& target, Int x = 0) {
	while (x*x < target) {
		x++;
	}
	return x;
}

int main() {
	while (not std::cin.eof()) {
		Int target;
		std::cin >> target;

		std::vector<Int> primes = {};
		Int sqrt = 0;
		for (Int n = 3; n <= target; n+=2) {
			bool flag = true;

			sqrt = sqrt_prm(n, sqrt);
			for (auto&& div : primes) {
				if (n > sqrt) { break; }
				if (n % div == 0) {
					flag = false;
					break;
				}
			}

			if (flag) {
				primes.push_back(n);
			}
		}

		std::cout << primes.size() + (target >= 2 ? 1 : 0) << std::endl;
	}
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	while (scanf("%d", &n) != EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n + 1)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

using namespace std;

const int Max=1000007;

bool visit[Max];
int prime[Max];
int num=0;
void init_prim()
{
    memset(visit, true, sizeof(visit));
    for (int i = 2; i <Max; ++i)
    {
        if (visit[i] == true)
        {
            num++;
            prime[num] = i;
        }
        for (int j = 1; ((j <= num) && (i * prime[j] <= 1000000));  ++j)
        {
            visit[i * prime[j]] = false;
            if (i % prime[j] == 0) break;
        }
    }
}

int main()
{
    int n;
    init_prim();
    while(~scanf("%d",&n))
    {
        int l=lower_bound(prime,prime+num,n)-prime;
        if(prime[l]>n)
            l=l-1;
        printf("%d\n",l);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <stdio.h>
using namespace std;

// Prime Number(0009(
int main()
{
	const int MAX = 1000000 + 1000;
	static bool prime[MAX];
	for (int i = 0; i < MAX; ++i)
		prime[i] = true;
	prime[0] = prime[1] = false;

	for (int i = 2; i < MAX; ++i) {
		if (prime[i]) {
			for (int j = i+i; j < MAX; j += i)
				prime[j] = false;
		}
	}

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