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>
using namespace std;
#define MAX 1000000

bool prime[MAX];

int countPrime(int n){
	if(n < 2) return 0;
	if(n == 2) return 1;

	int ret = 0;

	for(int i = 0; i < MAX; i++){
		prime[i] = true;
	}

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

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

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

using namespace std;

int prime(int n);

int main(){
  vector<int> inp;
  int num,pri;					
  int i=0;

  while(cin>>num){
    if(num <= 1)inp.push_back(0);
    else{
      pri = prime(num);
      inp.push_back(pri);
    }
    i++;
  }
  int j = 0;
  while(j < i){
    cout<<inp[j]<<endl;
    j++;
  }
}

int prime(int num){
  int count=0;
  bool judge=0;
  for(int i = 2; i <= num; i++){
    judge =1;
    for(int j= 2; j < i; j++){
      if(i%j == 0)judge =0;
    }
    if(judge==1)count = count +1; 
  }
  return count;
}

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

int count_prime_number(int n){
	if(n < 2){
		return 0;
	}
	int count = 1;	//2??????
	for(int i = 3; i <= n; i += 2){
		int k = 0;
		for(int j = 3; j <= sqrt(i); j += 2){
			if(i % j == 0){
				k=1;
				break;
			}
		}
		if(k==0){
			count++;
		}
	}
	return count;
}

int main(){
	vector<int> results;
	int in_num;
	while(cin >> in_num){
		results.push_back(count_prime_number(in_num));
	}
	for(auto result : results){
		cout << result << endl;
	}
	return 0;
}

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

void count_Prime(int n);
int IsPrime(int num);


int main()
{
	int Data = 0;

	cin >> Data;
//	while (cin >> Data)
		count_Prime(Data);

	return 0;
}

void count_Prime(int n)
{
	int counter = 1,  i = 0;
	for (i = 2; i < n; ++i)
		counter += IsPrime(i);		

	cout << counter << endl;

}

int IsPrime(int num)
{
	if (num < 2) return 0;
	else if (num == 2) return 1;
	else if (num % 2 == 0) return 0; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return 0;
		}
	}

	// ?´???°??§??????
	return 1;
}

C++: #include<stdio.h>
#define max 1000001

int main(void)
{
	int *d, f1, f2, n, cnt;
	d = new int [max];
	for(f1 = 0; f1 < max; f1++)
	{
		d[f1] = 1;
	}
	for(f1 = 2; f1 *f1 < max; f1++)
	{
		if(d[f1] == 1)
		{
			for(f2 = 2 * f1; f2 < max; f2 += f1)
			{
				d[f2] = 0;
			}
		}
	}
	while (scanf("%d",&n) != EOF)
	{
		cnt=  0;
		for(f1 = 2; f1 <= n; f1++)
		{
			if(d[f1] == 1)
				cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    prime[0] = false;
    prime[1] = false;
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    sieve();

    int memo[1000000];
    for (int i=1; i<1000000; ++i) {
        memo[i] = memo[i-1]; 
        if (prime[i]) {
            memo[i] ++; 
        }
    }

    int n;
    while (cin >> n) {
        cout << memo[n] << "\n";
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int n;
#define MAX_N 999999

int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数

// n以下の素数の数を返す
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() {
    sieve(MAX_N);
    cin>>n;
    int ans=0;
    for(int i=2;i<=n;i++) {
        if(is_prime[i]) ans++;
    }
    cout << ans << endl;
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
//#include<time.h>
using namespace std;

int main()
{
	
	long long int k,p[100000];
	long long int n;
	//time_t time1,time2;
	p[0]=2;
cin>>n;
	k=0;
	int r=(int)sqrt((float)n);
	for(int i=3;i<=r;i++){
		for(int j=0;j<k+1;j++){
			if(i%p[j]==0){
				break;
			}else if(j==k){
				k++;
				//cout<<i<<endl;
				p[k]=i;
			}
		}
	}
	long long int r_k=k;
	for(;r<n;r++){
		for(long int i=0;i<=r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k){
				k++;
				//cout<<r<<endl;
			}
		}
	}
	//time(&time2);
	if(k!=0&&k!=1){
		k+=1;
		cout<<k<</*"ツ古t\t"<<difftime(time2,time1)<<"minutes"<<*/endl;
	}else{
		cout<<k<</*"\t\t"<<difftime(time2,time1)<<"minutes"<<*/endl;
	}
	
}

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

using namespace std;


int count_less_or_equal_primes(int num) {
  vector<bool> is_primes(num + 1, true);

  is_primes[1] = false;

  double num_sqrt = sqrt(num);
  for(int i = 2; i <= num_sqrt; i++) {
    if(!is_primes[i]) {
      continue;
    }

    // Sift numbers
    for(int j = i + i; j <= num; j += i) {
      is_primes[j] = false;
    }
  }

  // Count left primes
  int prime_count = 0;
  for(int i = 1; i <= num; i++) {
    if(is_primes[i]) {
      prime_count++;
    }
  }
  return prime_count;
}

int main() {
  int num;

  while(cin >> num) {
    cout << count_less_or_equal_primes(num) << endl;
  }
}

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

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	int i, k, v;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	scanf("%d", &v);
	int count = 0;
	for(i=0;i<=v;i++){
		int isprime = prime[i];
		if(isprime) count ++;
	}
	printf("%d",count);
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    char x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-10;

int main(){
	vector<int> p;
	bool b;
	int n;

	while(cin >> n){
		p.clear();
		p.push_back(2);
		for(int i = 3; i <= n; i++){
			b = true;
			for(int j = 0; j < p.size(); j++){
				if(p[j]*p[j] > i){
					break;
				}
				if(i % p[j] == 0){
					b = false;
					break;
				}
			}
			if(b){
				p.push_back(i);
			}
		}
		cout << p.size() << endl;
	}

	return 0;
}

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


int main(){
	bool work[MAX + 1];
	int num, ans = 0;

	// 入力
	cin >> num;

	// 初期化
	for(int i = 0; i <= MAX; i++){
		if(i < 2){
			work[i] = false;
		}else{
			work[i] = true;
		}
	}

	// エラトネスのふるい
	for(int i = 2; i < sqrt((double)MAX) + 1; i++){
		if(work[i] == true){
			for(int j = i * 2; j < MAX; j += i){
				work[j] = false;
			}
		}
	}

	// 計算
	for(int i = 0; i <= num; i++){
		if(work[i] == true){
			ans++;
		}
	}

	// 出力
	cout << ans << endl;

	return 0;
}