Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

  for(int i=2;i*i<1000000;i++){
    if(a[i]){
      for(int j=i*i;j<10000000;j+=i){
        a[j]=false;
      }
    }
  }

  int n[1000000];

  int tmp=0;
  for(int i=0;i<1000000;i++){
    if(a[i]){
      tmp++;
    }
    n[i]=tmp;
  }

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }
    
    cout<<n[m]<<endl;

  }

  return 0;
}

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

int main(){

  int n;

  while(cin>>n){

	int cnt=0;
	
	if(n <= 1){
	  cout<<0<<endl;
	  continue;
	}

	else
	  cnt++;
	
	for(int i=3;i<=n;i+=2){
	  int f = true;
	  for(int j=3;j<i;j+=2){
		if(i%j==0){
		  f = false;
		  break;
		}
	  }
	  if(f == true)
		cnt++;
	}

	cout<<cnt<<endl;
	
  }

  return 0;
  
}

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

int whether(int num);
int count(int num);

int main(){
	int n;
	int a;
	int b;

	while(1){
		b=feof(stdin);
		if(b!=0) break;
		scanf("%d",&n);
		a = count(n);
		printf("%d\n",a); 
	}

	return 0;
}

int whether(int num){
	int s=sqrt(num);
	int i;
	for(i=3; i<=s; i+=2){ if(num%i==0) return 0; }

	return 1;
}

int count(int num){
	int a=1;
	int i;
	if(num <2){ return 0; }
	for(i=3; i<=num; i+=2){
		a += whether(i);
	}

	return a;
}

C++: #include <iostream>
#define MAX_N 1000000
using namespace std;
int main(){
	bool num[MAX_N];
	for(int i = 1; i < MAX_N; i++){
		num[i] = true;
	}
	num[0] = false;
	for(int i = 1; i < MAX_N; i++){
		if(num[i] == true){
			for(int j = 2*i+1; j < MAX_N; j += (i+1)){
				if((j+1) % (i+1) == 0){
					num[j] = false;
				}
			}
		}
	}
	int n;
	while(cin >> n){
		int prime = 0;
		for(int i = 1; i < n; i++){
			if(num[i] == true){prime++;}
		}
		cout << prime << endl;
	}
	return 0;
}

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

int main(){
	int  n,i,j,sqrtn,sum;
	while(scanf("%d",&n)!=EOF){
		sum=(n-1)/2;
		for(i=3;i<=n;i+=2){
			sqrtn=(int)sqrt(i);
			for(j=1;j*6-1<sqrtn;j++){
				if(i%(j*6+1)==0 || i%(j*6-1)==0){
					sum--;
					break;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
   vector<int> v(1000000,0),rui(1000000,0);
   rep(i,1,999999+1)if(isPrime(i))v[i]=1;
   rui[1]=v[1];
   rep(i,2,999999+1)rui[i]=rui[i-1]+v[i];
   
   int n;
   while(cin>>n){
       cout<<rui[n]<<endl;
   }
   
    
    return 0;
}

C++: #include <iostream>

int main() {
	bool p[1000000];
	p[0] = p[1] = true;
	for( int i=2; i<1000000; i++) p[i] = false;
	
	int q[1000000];
	for( int i=2; i<1000; i++) if(!p[i]) for( int j=i*i; j<1000000; j+=i) p[j] = true;
	
	int sum = 0;
	for( int i=0; i<1000000; i++) {
		if(!p[i]) sum++;
		q[i] = sum;
	}
	
	int n;
	while( std::cin >> n) {
		std::cout << q[n] << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int n, count;

	while ( cin >> n )
	{
		bool table[1000000];
		count = 0;

		for ( int i = 0; i <= n; i++ )
		{
			table[i] = true;
		}

		for ( int i = 2; i <= n; i++ )
		{
			if ( table[i] )
			{
				count++;
				for ( int j = 2; i * j <= n; j++ )
				{
					table[i*j] = false;
				}
			}
		}

		printf("%d\n", count );
	}

	return 0;
}

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

class SOSU{
   public:
      int sosu(int);
};
int SOSU::sosu(int n){
   int i,j,ans=0,flag;
   
   for(i=0;i<=n;i++){
      if(i<2)
         continue;
      
      else if(i==2 || i==3){
         ans++;
         continue;
      }
      
      if(i%2==0 || i%3==0)
         continue;
      
      flag = 0;
      for(j=2;j*j<=i;j++){
         if(i%j==0){
            flag++;
            break;
         }
      }
      if(flag==0)
         ans++;
   }
   return ans;
}

int main(){
   SOSU Sosu;
   int n,ans;
   while(cin>>n){
      ans = Sosu.sosu(n);
      printf("%d\n",ans);
   }
   return 0;
}

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

using namespace std;
#define MAX_NUM 999999

int main(){
  int n;
  bool flag = false;
  int numPrime[MAX_NUM];
  int pivot = 1;
  
  while(cin >> n){

    if(n < pivot){
      cout << numPrime[n] << endl;
      continue;
    }
    
    for(int i=pivot+1;i<=n;i++){
      flag = false;

      for(int j=2;j<=sqrt(i);j++){
	if(i%j==0){
	  flag = true;
	  break;
	}
      }
      
      if(flag){
	numPrime[i] = numPrime[i-1];
	continue;
      }else{
	numPrime[i] = numPrime[i-1] + 1;
      }
    }
    cout << numPrime[n] << endl;
  }
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

int t;

int main(){
	int *prime;
	prime = (int *)malloc(100010*sizeof(t));
	if(prime==NULL) cout<<"no mem\n";
	rep(i,100010){
		prime[i]=true;
	}
	prime[0]=prime[1]=false;
	for(int i=2;i*i<100010;i++){
		if(prime[i]){
			for(int j=i*i;j<100010;j+=i){
				prime[j]=false;
			}
		}
	}
	
	int *sum;
	int num=0;
	sum=(int *)malloc(100010*sizeof(t));
	if(sum==NULL) cout<<"no mem\n";
	rep(i,100010){
		if(prime[i]){
			num++;
		}
		sum[i]=num;
	}
	int n;
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	return 0;
}