Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
	vector<int> isPrime;
	
	while(cin>>n)
	{
		for(int i = 0; i < n; i++){
			isPrime.push_back(1);
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
//			printf("head:%d    fin:%d\n",head,fin);
			
			if(fin < head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
			}
		}
		printf("%d\n",cont);
	}
}

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

int main(){
  int MAX = 1000000;
  int n;
  int cnt=0;
  vector<bool> num(n);
  
  for(int i=0; i<MAX; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;

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

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

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

const int limit = 1000000;
bool prime[limit + 10];

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

int main() {
    era();
    int n;

    while(cin >> n) {
        int ans = 0;

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

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

bool w[1000000];
int a[1000000];

int main()
{
	for(int i = 0; i < 1000000; i++)
	{
		w[i] = true;
	}
	int all = 0;
	a[0] = 0;
	a[1] = 0;
	for(int i = 2; i < 1000000; i++)
	{
		if(w[i])
		{
			all++;
			for(int j = 2; i * j < 1000000; j++)
			{
				w[i * j] = false;
			}
		}
		a[i] = all;
	}
	while(1)
	{
		int n;
		if(EOF == scanf("%d",&n))
		{
			break;
		}
		printf("%d\n",a[n]);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
int vis[1000000];
int prime[10000];
int k=0;
void deal()
{
   memset(vis,0,sizeof(vis));
   for(int i=2;i*i<=999999;i++)
   {
      if(!vis[i])
      {
         prime[k++]=i;
         for(int j=i*i;j<=999999;j+=i)
         {
            vis[j]=1;
         }
      }
   }
}
int main()
{
   deal();
   int n;
   while(scanf("%d",&n)==1)
   {
      int sum=0;
      for(int i=0;i<k;i++)
      {
         if(prime[i]<=n)
            sum++;
         else break;
      }
      cout<<sum<<endl;
   }
   return 0;
}

C++: #include<iostream>

using namespace std;

int prime[1000000];
bool is_prime[1000000];


int sieve(int n){

  int p=0;
  for(int i =0;i<=n;i++)is_prime[i] = true;
  is_prime[0] = is_prime[1] =false;

  for(int i = 2;i<=n;i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j = 2*i;j<=n;j+=i)is_prime[j] = false;
    }

  }
  return p;

}


main(){
  
  int n;

  while(cin >> n){
    
    cout << sieve(n) << endl;
    

  }


  return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main() {

	int n,count;

	while (cin >> n) {
		count = 0;
		
		//?´???°????????????????¨???¶?????????????????????????¢????
		bool *is_prime;
		is_prime = (bool *)malloc(n+1);
		if (is_prime == NULL) {
			cout << "malloc error" << endl;
			break;
		}

		//????????¨????´???°??§????????¨??????
		for (int i = 0; i <= n; i++) {
			is_prime[i] = true;
		}

		for (int i = 2; i <= n; i++) {
			//?´???°???????????§????????£???????????????????????§??????
			if (is_prime[i] == true) {
				//????????°???????????§????????°????????£?????????
				for (int j = i+1; j <= n; j++) {
					//cout << "i=" << i << " j=" << j << " is_prime(i)=" << is_prime[i] << " is_prime(j)=" << is_prime[j] << endl;
					if (is_prime[j] == true) {
						if (j%i == 0) {
							//????????????????????????????´???°??§?????????
							is_prime[j] = false;
						}
					}
				}
			}
		}

		//?´???°??¨?¢????????????°????????°????????????
		for (int i = 2; i <= n; i++) {
			if (is_prime[i] == true) {
				count++;
				//cout << " " << i;
			}
		}

		//??¨???
		cout << count << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool isprime[1000000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 1000000; i++) {
		isprime[i] = true;
	}
	while (cin >> n && checkcnt < 30) {
		cnt = 0;
		int i;
		for (i = 2; i <= sqrt(n); i++) {
			if (isprime[i]) {
				for (int j = 2; j <= n / i; j++) {
					isprime[i * j] = false;
				}
			}
		}
		for (int k = 2; k <= n; k++) {
			if (isprime[k]) {
				cnt++;
			}
		}
		cout << cnt << endl;
		checkcnt++;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int prime[1000005],e;
bool is_prime[1000005];
int presum[1000005];
void solve()
{
    prime[0]=prime[1]=1;
    for(int i=2;i<=1000000;i++)
    {
        if(!is_prime[i])
        {
            prime[++e]=i;
            if((long long)i*i>1000000) continue;
            for(int j=i*i;j<=1000000;j+=i) is_prime[j]=1;
        }
    }
}
void pre()
{
    presum[0] =presum[1]= 0;
    for(int i = 2; i <=1000000; i++)
        presum[i] = is_prime[i] ? presum[i - 1]: presum[i - 1]+1;
}
int main()
{
    int n;
    solve();
    pre();
    //cout<<e;
    while(cin>>n)
    {
       cout<<presum[n]<<endl;
    }

   return 0;
}

C++: #include<iostream>
using namespace std;
bool prime(int n){
	for(int i=2;i<n;i++){
		if(n%i==0)return false;
	}
	return true;
}
int main(){
	int a;
	while(cin>>a){
	int sum=0;
	for(int j=2;j<a;j++){
		if(prime(j))sum++;
	}
	cout<<sum<<endl;
	}
}

C++: #include <iostream>
//#include <vector>
//#include <math.h>
//#include <string>
//#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}