Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

using namespace std;
#define MAX_NUM 10000000
vector<int> p;
int flag[MAX_NUM/32+1];

//sieve eratosthenes
void setPrime(vector<int> &p){

    for(int i=1;2*i*(i+1)<(MAX_NUM>>1);++i){

        if(flag[i>>5] & (1<<(i%32)))continue;
        //(2*j+1) == (2*i+1)*(2*i+1)
        //(2*i+1)*(2*i+1) -> (2*i+1)*(2*(i+1)+1) -> ... set not prime
        for(int j=2*i*(i+1); j<(MAX_NUM>>1); j+=2*i+1)
            flag[j>>5] |= (1<<(j%32));

    }

    p.push_back(2);
    for(int i=1;2*i+1<=MAX_NUM;++i){
        for(;flag[i>>5] & (1<<i);++i);
        if(2*i+1>MAX_NUM)break;
        p.push_back(2*i+1);
    }

}

int ans[1000001];
int cnt = 0;

int main(){

    vector<int> primes;
    setPrime(primes);

    for(int i=0;i<=1000000;++i){

        if(primes[cnt]==i)++cnt;

        ans[i]=cnt;

    }

    int N;
    while(cin>>N){

        cout << ans[N] << endl;

    }

    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

#pragma warning(disable:4996)

int main()
{
	int DataSet,nCnt,nCnt2,In,Total,Count;

	Total = 0;
	DataSet = 0;

	for (DataSet = 0; DataSet <= 30; DataSet++)
	{
		scanf("%d", &In);
		Total = 1;

		if (In > 2)
		{
			for (nCnt = 3; nCnt <= In; nCnt += 2)
			{
				Count = 0;

				for (nCnt2 = nCnt; nCnt2 >= 2; nCnt2--)
				{
					if (nCnt%nCnt2 == 0)
					{
						if (nCnt != nCnt2)
						{
							Count++;
							break;
						}
					}
				}
				if (Count == 0)
					Total++;
			}
		}

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


	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<math.h>
using namespace std;
  
int main(){
int p;
while(cin>>p){	int n[100001],i,j,a=0;
	for(i=0;i<100001;i++){
		n[i]=0;
	}
	n[0]=1;n[1]=1;
	for(i=2;i<100000;i++){
		if(n[i]==0){
			j=2;
			while(i*j<100000){
				n[i*j]=1;
				j++;
			}
		}
	}
	for(i=1;i<p;i++){
		if(n[i]==0){
			a++;
		}
	}
	cout<<a<<endl;
}
	return 0;
}

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

using namespace std;

int A[1000000];
int Pream(int n)
{
	int kusa = (int)sqrt((double)n);
	int mama = 0;

	for (int i = 0; i < n; i++)
		A[i] = 1;  // ??¨????????°???1????????????
	A[0] = 0;    // 1????´???°??§?????????

	for (int i = 1; i < kusa; i++) {
		if (A[i] == 1)   // prime[i]????´???°??????
		{
			for (int j = (i + 1); (i + 1) * j <= n; j++)
				A[(i + 1) * j - 1] = 0;  // ?´???°????????°????´???°??§?????????
		}
	}
	for (int i = 0; i < n; i++)
		if (A[i] == 1)  // 1????????£???????????????????´???°
			mama++;

	return mama;
}

int main()
{
	int n;
	cin >> n;
	while (n != -1)
	{
		cout << Pream(n) << endl;
		cin >> n;
	}
	return 0;
}

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

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j] = true;
		}
		t[i]=t[i-1]+!c[i];
	}
	for(int n;cin>>n;n++){
		cout << t[n] << endl;
	}
	return 0;
}

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

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

int main(){
	int n;
	int a;
	clock_t c, d;

	while(1){
		if(scanf("%d",&n) != -1) break;
		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>
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;
}