Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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;
}

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;
}