Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for (int a = 3; a<1000000; a++)
	{
		prime[a] = 1;
	}

	for (int a = 3; a<1001; a++)
	{
		if (checked[a] == 0)
		{
			checked[a] = 1;
			for (int b = 2; b<a; b++)
			{
				if (a%b == 0)
				{
					prime[a] = 0;
					break;
				}
			}
			if (prime[a] == 1)
			{
				for (int c = 2 * a; c<1000000; c += a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for (int a = 3; a<1000000; a++)
	{
		primesum[a] = primesum[a - 1] + prime[a];

	}

	while (cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}

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

/** Problem0009 : Prime Number **/
#define MAX 1000000

int main()
{
	bool prime[MAX];
	int  input, count;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin >> input) {
		count = 0;
		for (int i=0; i<=input; i++) {
			if (prime[i]) count++;
		}
		cout << count << endl;
	}
}

C++: #include <iostream>                                                                                                     
#include <vector>                                                                                                       
                                                                                                                        
using namespace std;                                                                                                    
                                                                                                                        
int main() {                                                                                                            
  int n;                                                                                                                
  cin >> n;                                                                                                             
                                                                                                                        
  if (n == 1) { cout << 0 << endl; return 0; }                                                                          
  if (n == 2) { cout << 1 << endl; return 0; }                                                                          
                                                                                                                        
  vector<int> prime_numbers; // 素数リスト                                                                              
  int c = 1;                                                                                                            
  prime_numbers.push_back(2);                                                                                           
  for (int i = 3; i <= n; i++) {                                                                                        
    bool prime = true;                                                                                                  
    for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) {                        
      if (i % *itr == 0) {                                                                                              
        prime = false;                                                                                                  
        break;                                                                                                          
      }                                                                                                                 
    }                                                                                                                   
    if (prime) {                                                                                                        
      prime_numbers.push_back(i);                                                                                       
      c += 1;                                                                                                           
    }                                                                                                                   
  }                                                                                                                     
  cout << c << endl;                                                                                                    
  return 0;                                                                                                             
}

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

const int max_n = 1000000;
int prime[max_n];
bool is_prime[max_n+1];

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;
}

int main()
{
	int n;
	cin >> n;
	cout << sieve(n) << endl;
	return 0;
}

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

int main(){
	int m=0,n;
	cin>>n;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define L(_i,_N) for(int _i=0;_i<_N;_i++)
#define C(_Dis) cout<<_Dis<<endl;

using namespace std;

typedef long long int lli;

int main() {
	int n,Count=0;
	while (cin >> n) {
		vector<bool> ch(n+1);
 		for (int i = 2; i <= n; i++) ch[i] = true;
		for (int i = 2; i <= n; i++) {
			if (ch[i]) Count++;
			for (int j = i * 2; j <= n; j += i) ch[j] = false;
		}
		C(Count);
		Count = 0;
	}
	return 0;
}

C++: #include <iostream>
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 res;
scanf("%d",&n);
for(int i=2;i<=n;i++){
if(is_prime(n)) res = i;
}
printf("%d\n",res);
}

C++: #include <stdio.h>

int isPrime(int n);

int main(void){
    int n;
    int cnt;

    while (scanf("%d", &n)!= EOF){
        cnt = 0;
        for(int i=2; i<=n; i++){
            if (isPrime(i)) cnt++;
        }
        printf("%d\n", cnt);
    }

    return 0;
}


int isPrime(int n){
    int i;
    
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int prime(int n){
	int prime;
	if(n==2) prime=1;
	else if(n==3){
		prime=2;
	}
	else{
		prime=2;
		for(int i=5;i<=n;){
			int m=sqrt((double)i);
			for(int j=3;j<=m+1;j++){
				if(i%j==0) break;
				else{
					if(j==m+1) prime++;
				}
			}
			i += 2;
		}
	}
	return prime;
}

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