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>
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;
	while(cin >> n)
		cout << sieve(n) << endl;
	return 0;
}

C++: #include <cstdio>

const int NUM = 1000000;
bool prime[NUM];
int primeNum[NUM];

int main(){

  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

	for(int i=0,c=0;i<NUM;i++){
		prime[i]&&c++;
		primeNum[i] = c;
	}
	for(int n;scanf("%d",&n)+1;printf("%d\n",primeNum[n]));
}

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

using namespace std;

int main(void) {
	int n;
	
	vector<int> prmcnt_v;

	while(cin >> n) {
		int pcnt = 0;
		for (int i = 2; i <= n; i++) {
			for (int j = 2; j <= i; j++) {
				if (j % 2 == 0 && j != 2) {
					continue;
				}

				if (i % j == 0){
					if (i == j) {
						pcnt++;
					}
					else {
						break;
					}
				}
			}
		}
		prmcnt_v.push_back(pcnt);
	}


	for (int k = 0; k < prmcnt_v.size(); k++) {
		cout << prmcnt_v[k] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 1e6+7;
int prime[maxn];
bool is_prime[maxn];
int n,p=-1;

void Eular()
{
    for(int i=1;i<=maxn-7;i++)
        is_prime[i]=true;
    for(int i=2;i<=maxn-7;i++)
    {
        if(is_prime[i])
            prime[++p]=i;
        for(int j=0;j<=p && i*prime[j] <= maxn-7;j++)
            is_prime[i*prime[j]]=false;
    }
}

int main()
{
    Eular();
    while(~scanf("%d",&n))
    {
        int i=0,ans=0;
        while(i<=p && prime[i]<=n) i++,ans++;
        printf("%d\n",ans);
    }
    return 0;
}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int n, cnt=0;
    for(;cin>>n;){
        for(int i = 3; i<=n; i+=2){
            int k= 0;
            for(int j=3; j<sqrt(i); j+=2){
                if(i%j==0){
                    k=1;
                    break;
                }
            }
            if(k==0) cnt++;
        }
        printf("%d\n", cnt);

    }

    return 0;
}

C++: #include <stdio.h>

int main(void) {
	int i,ii,t,mn;
	while(scanf("%d", &mn) != EOF){
		t = 0;
		for(i = 2;i <= mn;i++){
			t++;
			for(ii = 2;ii < i;ii++){
				if (i % ii == 0){
					t--;
					break;
				}
			}
		}
		printf("%d\n",t);
	}
	return 0;
}

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

using namespace std;

bool judge(int);

int main(){
	const int MAX_VALUE = (int)1e7;
	vector<bool> primeNums(MAX_VALUE);
	
	for(int i = 1; i < MAX_VALUE; i ++)
		primeNums[i]=judge(i);

	for(int n, count = 0; cin >> n; cout << count << endl, count = 0)
		for(int i=1; i<=n; i++) if(primeNums[i]) count++;

	return 0;
}

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

	return true;
}

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

#define N 1000000

using namespace std;

int pn[N];

void Eratosthenes()
{
	for (int i=0; i<N; i++) {
		pn[i] = 1;
	}

	for (int i=2; i < (int)sqrt((double)N); i++) {
		if(pn[i]) {
			for (int j=0; i*(j+2)<N; j++) {
				pn[i*(j+2)] = 0;
			}
		}
	}
}

int main()
{
	int n;

	Eratosthenes();

	while (cin >> n)
	{
		int cont = 0;
		for (int i=2; i<=n; i++) {
			if(pn[i])	cont++;
		}

		cout << cont << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n,a,b,c;
    char x[1000000];
    while(~scanf("%d",&n)){
        memset(x,0,sizeof(x));
        for(a=2,c=0;a<=n;a++){
            if(x[a])continue;
            c++;
            for(b=a*2;b<=n;b+=a)x[b]=1;
        }
        printf("%d\n",c);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
#define MAX_N 999999
bool prime_check(int n, int k = 2){
	if (n < k * k) return true;
	if (n % k == 0) return false;
	return prime_check(n, k + 1);
}
int main(){
  int n;
  bool isprime[MAX_N+1];
  for(int i=2; i<=MAX_N; i++) isprime[i] = prime_check(i);
  while(cin >> n){
    int cnt=0;
    for(int i=2; i<=n; i++){
        if(isprime[i] == true) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>
#define N 100000
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
const int MAX_V = 1000000; // 100????????§?´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????? 
int pcount[MAX_V+1];
int main() {
    int i, k,a,sum=0;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1; // 2??\????´???°??¨??????
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°2?????\????????°?´???°??§?????? 
            }
            
        } 
        
    }
    pcount[0]=0;
    pcount[1]=0;
    for(i=2;i<MAX_V;i++){
        if(prime[i]){
            sum++;
        }
        pcount[i]=sum;
    }
    for(i=0;i<30;i++){
        scanf("%d",&a);
        printf("%d\n",pcount[a]);
    } 

    return 0; 
    
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int isPrime(int n) {
	if (n == 2) {
		return 1;
	}
	if ((n <2) || (n % 2 == 0)) {
		return 0;
	}
	int i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0) {
			return 0;
			
		}
		i += 2;
	}
	return 1;
}
int main()
{
	int x[30];
	int i = 0;
	while (cin >> x[i]) {
		int k = 0;
		for (int j = 0; j < x[i]; j++) {
			
			k += isPrime(j+1);
		}
		cout << k << endl;

		i++;
	}
	return 0;
}

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

bool isPrime(int num) {
    if(num < 2) return(false);
    for(int r = 2; r * r <= num; r++) {
        if(num % r == 0) return(false);
    }
    return(true);
}

int main(void) {
    int num;
   
    while(cin >> num) {
        int prime[num + 1];
        memset(prime, -1, sizeof(prime));
        prime[0] = prime[1] = 0;
        int sum = 1;
        
        for(int r = 3; r <= num; r += 2) {
            if(prime[r] != -1) continue;
            if(prime[r] % 2 == 0) continue;
            if(isPrime(r)) {
                prime[r] = 1;
                sum++;
                for(int c = 2 * r; c <= num; c += r) prime[c] = 0;
            }
        }
        
        cout << sum << endl;
    }
}