Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans = 1;
    for(int i = 3; i<=n; i+=2){
      bool isSosu = true;
      for(int j=3; j <= floor(sqrt(i)); j++){
        if(i%j == 0){
          isSosu = false;
          break;
        }
      }
      if(isSosu){
        ans++;
      }
    }
    cout << ans << endl;;
  }
  return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
bool n[1000000]={0};
bool prime(int n){
	for(int i=2;i<=sqrt ((double)n);i++){
		if(n%i==0)return false;
	}
	return true;
}
int main(){
	for(int k=2;k<=999999;k++){
		if(prime(k))n[k]=true;
	}
	int a,sum=0;
	while(cin>>a){
	for(int j=2;j<a;j++){
		if(n[j])sum++;
	}
	cout<<sum<<endl;
	sum=0;
	}
}

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

int main(){

  int n,i,j,ans;


  while(cin >> n){
    ans = 0;

    for(;n > 1 ; n--){
      if(n == 2 ) ans++;
      for(i = 2 ; i <= n/2 ; i++){
	if(n%i == 0){
	  break; 
	}
      }
      if(n%i != 0){
	ans++;
      }
    }
    cout << ans << endl;

  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=999999+10;
int n,cnt;
int pre[maxn],prime[maxn];
int bina_search(int l,int r){
	int mid=(l+r)/2;
	if((prime[mid]<n&&prime[mid+1]>n)||prime[mid]==n)
		return mid;
	if(prime[mid]<n)
		bina_search(mid+1,r);
	else
		bina_search(l,mid);
}
int main(){
	memset(pre,0,sizeof(pre));
	memset(prime,0,sizeof(prime));
	int t=1;
	for(int i=2;i<maxn;i++){
		if(!pre[i])
			prime[t++]=i;
		for(int j=1;j<=t&&i*prime[j]<maxn;j++){
			pre[prime[j]*i]=prime[j];
			if(i%prime[j]==0)
					break;
		}
	}
	while(scanf("%d",&n)!=EOF){
		cnt=bina_search(2,n);
		printf("%d\n",cnt);
	}
	return 0;
}

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

using namespace std;

bool judge_Prime_num(const int& num) {
	if (num < 2)
		return false;
	else if (num == 2)
		return true;
	else if (num % 2 == 0)
		return false;

	double sqrtnum = sqrt(num);
	for (int i = 3; i <= sqrtnum; i += 2) {
		if (num%i == 0)
			return false;
	}
	return true;
}

int main() {
	int n;
	while (cin >> n) {
		int tmp = n;
		int cnt = 0;
		while (tmp > 1) {
			if (tmp != 2 && tmp % 2 == 0) {
				--tmp;
				continue;
			}
			if (judge_Prime_num(tmp)) {
				++cnt;
			}
			--tmp;
		}
		cout << cnt << endl;
	}
}

C++: #include <cstdio>
const int N=1000000;
int p[N],pN[N];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)p[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i]=c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

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

int main(void){
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 )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}
}

C++: #include<iostream>

using namespace std;

int main(){
	int n, prime[1000000], ans[1000000];


	for (int i = 0; i<1000000; i++)prime[i] = ans[i] = 0;
	prime[0] = prime[1] = 1;

	for (int i = 2; i*i<1000000; i++)
	if (prime[i] == 0)
	for (int j = 2 * i; j<1000000; j += i)
		prime[j] = 1;

	int cnt = 0;
	for (int i = 0; i<1000000; i++){
		if (prime[i] == 0)cnt++;
		ans[i] = cnt;
	}

	while (cin >> n)
		cout << ans[n] << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

	int p = 0;
	fill(is_prime, is_prime + n + 1, 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;
		}
	}

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}


int main(void){
	int n;
	while(scanf("%d", &n)){
		if(n == EOF) break;
		cout << sieve(n) << '\n';
	}

	return 0;
}

C++: #include <iostream>

bool prime(int n);

int main(void) {
	using namespace std;
	int x;
	while (cin >> x) {
		int count = 0;
		for (int i = x; i > 1; i--) {
			if (prime(i))count++;
		}
		cout << count << endl;
	}
	return 0;
}

bool prime(int n) {
	for (int i = n - 1; i > 1; i--) {
		if (n % i == 0)return false;
	}
	return true;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a[30],b,c=0,d=0;
	int flg=0;
	while(cin>>a[d]){
		for (int A=2;A<=a[d];A++){
		flg=0;
			for (int B=2;B<=A;B++){
				b=A%B;
				if (A==B){
					c++;
					break;
				}
				if (b==0) break;
			}
		}
		cout<<c<<endl;
		c=0;
		d++;
	}
	return 0;
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

using namespace std;

int main()
{
    int n;

    while (cin>>n){
        int count=0;

        while (1 < n){
            int prime_flag=1;
            for (int j = n - 1; prime_flag && 1 < j; j--) {
                if(n % j==0){
                    prime_flag=0;
                }
            }
            count+=prime_flag;
            n--;
        }
        cout<<count<<endl;
    }
    return 0;
}

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

bool check(int in){
	for (int i = 3; i<=sqrt(in); i+=2){
		if (i != 5 && i % 5 == 0)	continue;
		if (in % i == 0)
			return false;
	}
	return true;
}

int PrimeNumber(int in, int start){
	int count = 0;
	if (in > 2)	count++;
	for (int i = start; i <=in; i+=2){
		if (check(i))	count++;
	}

	return count;
}

int main(){
	int in;
	int count250000 = PrimeNumber(250000, 3);
	int count500000 = count250000 + PrimeNumber(500000, 250001);
	int count750000 = count500000 + PrimeNumber(750000, 500001);

	while (cin >> in, !cin.eof()){
		if (in <= 250000)
			cout << PrimeNumber(in, 3) << endl;
		else if (in <= 500000)
			cout << count250000 + PrimeNumber(in, 250001) << endl;
		else if (in <= 750000)
			cout << count500000 + PrimeNumber(in, 500001) << endl;
		else
			cout << count750000 + PrimeNumber(in, 750001) << endl;
	}
}

C++: #include <iostream>

using namespace std;

int sang(int n,bool *s,int *p,int &m){
	m = 0;
	for(long i = 2; i<=n;i++){
		s[i] = 2;
	}
	for(long i = 2; i<=n; i++){
		if(s[i]){
			p[m++] = i;
			for(long j = i * i; j<= n ; j += i){
				s[j] = 0;
			}
		}
	}
	return m;
}
int main(){
	int test =0;
	bool s[100005];
	int n,p[100005],m;

	while(test <999999){
		cin>>n;
		sang(n,s,p,m);
		cout<<m<<endl;
		test++;
	}
	return 0;
}