Go: package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	//"math"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		fmt.Println(calc(n))
	}
}

func calc(n int)int{
	// エラトステネスで数え上げる
	// 最初から999999まで用意しておいて入力のたびO(1)で出すのとどっちが速いのかはわからん
	eratos := make([]bool, n+1)
	c := 0
	for i:=2; i<len(eratos); i++{
		if eratos[i] == false{
			c++
			for j:=i*i; j<len(eratos); j+=i{
				eratos[j]=true
			}
		}
	}
	return c
}

func next()string{
	return sc.Text()
}

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <iostream>
using namespace std;
int main()
{
	int P[1000000] = {};
	int c = 0, j, k;
	for (k = 2; k < 1000000; ++k){
		if (P[k] == 0){
			++c;
			for (j = 2; j * k < 1000000; ++j)
				P[j * k] = -1;
		}
		P[k] = c;				
	}
	while (cin >> k)
		cout << P[k] << "\n";
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int count1,count2;
  while(1){
    cin >>n;
    count2=0;
    for(int i=n;i>1;i--){
      count1=0;
      for(int j=2;j<i;j++){
	if(i%j==0){
	  count1++;
	  break;}
      }
      if(count1==0)count2++;}
      cout <<count2<<endl;
    }
  return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main()
{
    int n;
    set<int> prime;
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            bool is_prime = true;
            int tmp = 2;
            for(auto num : prime)
            {
                if(num >= i) break;
                if(i % num == 0)
                {
                    is_prime = false;
                    break;
                }
                tmp = num;
            }
            for(int j = tmp; is_prime && j <= i / 2; j++)
            {
                if(i % j == 0)
                {
                    is_prime = false;
                    break;
                }
            }
            if(is_prime) 
            {
                prime.insert(i);
            }
        }
        int cnt = prime.size();
        for(auto it = prime.rbegin(); it != prime.rend(); it++)
        {
            cerr << *it << ' ';
            if(n < *it) cnt--;
            else break;
        }
        cout << cnt << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main() {
  int prime_flag[1000000];
  FOR(i, 2, 1000000) prime_flag[i] = 1;
  int t = 2;
  while(t < 1000000/2) {
    if(prime_flag[t]) {
      int k = 2;
      while(t * k < 1000000) {
	prime_flag[t*k] = 0;
	k++;
      }
    }
    t++;
  }
  int n;
  while(scanf("%d", &n) != EOF) {
    t = 0;
    REP(i, n+1) t += prime_flag[i];
    printf("%d\n", t);
  }
  
  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 <iostream>
using namespace std;

bool isprime(int n){
    if(n==0 || n==1){
        return false;
    }
    if(n==2){
        return true;
    }
    for(int i=2;i<n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

int solve(int x){
    int m = 0;
    for(int i=0;i<=x;i++){
        if(isprime(i)){
            m++;
        }
    }
    return m;
}
int main(){
    int n;
    while((cin>>n)){
        cout << solve(n) << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    int x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        c++;
        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 <stdio.h>
#include <math.h>

int main(){
    long long n, i, j, yaku, count;
    while (scanf("%lld",&n) != EOF) {
        count=1;
        if (n==1) {
            printf("%d\n",0);
        }
        else if (n==2){
            printf("%d\n",1);
        }
        else{
            for (i=3; i<=n; i+=2) {
                yaku=0;
                for (j=3; j<=sqrt(i); j+=2) {
                    if (i%j == 0) {
                        yaku=1;
                        break;
                    }
                }
                if (yaku == 0) {
                    count++;
                }
            }
            printf("%lld\n",count);
        }
    }
    
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

int prime[1000000] = {};

signed main() {
	int n;
	fill( prime, prime + 1000000, 1 );

	FOR( i, 2, 1000000 ) {
		if( prime[i] ) {
			for( int j = i * i; j < 1000000; j += i ) {
				prime[j] = 0;
			}
		}
	}

	while( cin >> n ) {
		int cnt = 0;
		FORE( i, 2, n ) {
			if( prime[i] ) cnt++;
		}
		cout << cnt << endl;
	}
}

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

int main(){
  int input;

  while(scanf("%d",&input) != EOF){
    int count = 1;

    for(int i = 3;i <= input;i += 2){
      bool isPrime = false;
      
      for(int s = 3;s <= sqrt((float)i);s += 2){
        if(i % s == 0){isPrime = true; break;}
      }
      if(!isPrime)count++;
    }
    printf("%d\n",count);
  }

  return 0;
}

C++: #include <iostream>
#include <cstdlib>
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;

while(~scanf("%d",&n)){
int* table =  new int[1000000];
memset(table,sizeof(table),1);
table[0]=0;

for(int i=1;i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j*=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+1000000,1));
}
}

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

int CheckNum(int input){
	int count = 0;

	for(int i = 2; i < input; ++i){
		for(int j = 2; j < i + 1; ++j){
			if( i % j == 0){
				if(!(i == j)) break;
				++count;
			}
		}
	}
	return count;
}

int main () {
	int input;

	while(cin >> input)
	cout << CheckNum(input) << '\n';

	return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[1000000];
	int count;


	while(scanf("%d",&n)!=EOF){
		count=0;
		c[0]=c[1]=0;
		for(i=2;i<=n;i++){
			c[i]=1;
		}
		
		for(i=0;i*i<=n;i++){
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0)c[j]=0;
				}
			}
		}


		for(i=0;i<=n;i++){
			if(c[i]==1){
				count++;
			}
		}

		printf("%d",count);


	}





	return 0;
}

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

int main(){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
	if (b == 0){
		cout << 0 << endl;
	}else{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
	}
}

}