Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

int p_num[1000000] = {} ;
int d[1000000] = {} ;

void cal(){
	for( int i=2 ; i<1000000 ; i++ ){
		if( p_num[i] == 0 ){
			for( int j=2 ; j<1000000 ; j++ ){
				if( i*j > 1000000 ) break ;
				p_num[i*j] = 1 ;
			}
		}
	}
	
	for( int i=2 ; i<1000000 ; i++ ){
		if( p_num[i] == 0 ) d[i] = d[i-1] +1 ;
		else d[i] = d[i-1] ;
	}
}

int main(){
	
	cal() ;
	
	int n ;
	while(1){
		cin >> n ;
		if( cin.eof() ) break ;
		
		cout << d[n] << endl ;
	}
	
return 0 ;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
//素数かどうかが真のものの数（カウントアップ）を返す
int countup(vector<bool>::iterator begin, vector<bool>::iterator end) 
{
    int counter = 0;
    while (begin++ != end) {
        if (*begin) 
            counter++;
    }
    return counter;
}
int main()
{
    int n;
    
    while (cin >> n) {
        int                     max = sqrt(static_cast<double>(n));
        vector<bool>            is_prime(n, true);
        vector<bool>::iterator  begin, end;
 
        is_prime[0] = is_prime[1] = false;
        
        for (int i=2; i<=max; i++) {
            if (!is_prime[i]) {
                continue;
            }
            else { // iがもし素数だったら、(自分以外の)その倍数全部潰す
                for (int cntr = 2, j = 2*i; j<=n; j = i*(cntr++)) { 
                    is_prime[j] = false;
                }
            }
        }
        begin   = is_prime.begin();
        end     = is_prime.end();
        cout << countup(begin, end) << endl;
    }
}

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

int main(){
	const int max_num=1000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

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

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
// have you mooed today?
bool isprime(int& num)
{
    static int c;
    static int max;
    max = sqrt(num) + 5;
    if(num == 2) return true;

    for(c=3; c < max; c+=2)
        if(num % c ==0) return false;
    return true;
}

main()
{
    int ans;
    int buff;
    while(cin >> buff)
    {
        ans  = 0;
        for(int d =2; d <= buff; d++)
        {
            if(isprime(d)) ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <vector>
#define MAX 100000
using namespace std;

int main(){
  //bool num[MAX];
  pair<bool,int> num[MAX];
  int count=0;
  int input=0;
  cin >> input;
  for(int i=2; i<MAX; i++){
    num[i].first=true;
    num[i].second=i;
  }
  for(int i=2;i<input+1;i++){
    if(num[i].first){
      //cout << num[i].second <<",";
      count++;
      for(int j=i+i; j<MAX; j+=i){
        num[j].first=false;
      }
    }
  }
  cout << count << endl;
//cout << MAX <<"までの素数の個数:"<< count  << endl;
  return 0;
}

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

#define pb push_back

using namespace std;

const int MAX=100000;
int main(void)
{
	int x;
	bool p[MAX];
	int cnt;
	int i1,i2;

	fill(p,p+MAX,false);

	for(i1=2;i1<MAX;i1++){
		for(i2=2;i2*i2<=i1;i2++){
			if(i1%i2==0) break;
		}
		if(i2*i2>i1) p[i1]=true;
	}

	while(cin>>x){
		cnt=0;
		for(i1=0;i1<=x;i1++){
			if(p[i1]) cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	int a[10000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n){
	
	int cnt = 0;
	for(int i = 2; i <= n; ++i){
		bool check = true;
		for(int j = 2; i >= j * j; ++j){
			if(i % j == 0){
				check = false;
				break;
			}
		}
		if(check)
			cnt++;
	}
	
	cout << cnt << endl;
	
	}
	
	return 0;
}

C++: #include<iostream>
#include<map>
#define M 999999
using namespace std;
int Prime[999999];
void sang()
{
for(long i=3;i<=M;i+=2) Prime[i]=1;
Prime[0]=Prime[1]=0;
Prime[2]=1;
for(long i=2;i<=M/i;i++)
if(Prime[i]==1)
{
for(long j=i*i;j<=M;j+=i) Prime[j]=0;
}
for(long long i=0;i<=M;i++){
			Prime[i]+=Prime[i-1];
	    }
}
int main()
{
	sang();
	long long n;
	while(1){
		cin>>n;
	    cout<<Prime[n]<<endl;
	}
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int yakusuu(int i){
	int counter=0;
	for (int j = 1; j <= i; j++){
		if (i%j == 0) counter++;
	}
	return counter;
}


int main()
{
	int n;
	while (scanf("%d",&n)!=-1)
	{
		int counter1 = 0;
		for (int i = 2; i <= n; i++)
		{
			if (yakusuu(i) == 2) counter1++;
		}
			cout << counter1 << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

const int Max = 10000000;
bool prime[Max];
int main()
{
  int in;
  for(int i=0; i<Max; i++){
    prime[i] = true;
  }
  prime[1] = false;
  for(int i=2; i<Max; i++){
    if(prime[i]){
      for(int s=i*2; s<=Max; s+=i){
	prime[s] = false;
      }
    }
  }
  while(cin>>in){
    int cnt=0;
    for(int i=1; i<=in; i++){
      if(prime[i]){
	cnt++;
      }
    }
      cout << cnt << endl;
  }
}

C++: #include<stdio.h>
#include<math.h>
int judge(int n){
	int i;
	for(i=2;i<=sqrt(n);i++){
		if(n%i==0){
			return 0;
		}
	}
	return 1;
}
main(){
	int i,n;
	int sum=0;
	scanf("%d",&n);
	for(i=2;i<n;i++){
		sum+=judge(i);
	}
	printf("%d\n",sum);
}

C++: int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    memo_prime.at(0) = memo_prime.at(1) = false;
    memo_prime.at(2) = true;
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

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