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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;

int main()
{
	int n;
	
	while (cin >> n) {
		int count = 0;
		for (int i = 2; i <= n; i++) {
			int ope = 1;
			for (int j = 2; j*j <= i; j++) {
				if (i%j == 0) {
					ope = 0;
					break;
				}
			}
			count += ope;
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int num[1000001]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=1000000;i++)
	num[i]=1;
for(int i=2;i<=1001;i++){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,z,x;
	
    scanf("%d",&n);
	while(n<2){
		for(i=2;i<=n;i++){
			z=0;
			for(j=2;j<=i;j++){
				if(i%j==0 && i!=j){
					z++;
					break;
				}
			}
			if(z==0){
				x++;
			}
		}
		printf("%d\n",x);
		scanf("%d",&n);
	}
	return 0;
}

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

using namespace std;

int ans = 0;

void Prime_number(int n){
	int i;
	int prime_num;

	for(i = 2; ; i++){
		if(n % i == 0 && n != i){
			break;
		}else if(n == i){
			ans++;
			break;
		}
	}

	if(n != 2){
		Prime_number(n-1);
	}
}

int main(){
	int n;

	while((scanf("%d",&n)) != EOF){
		Prime_number(n);
		cout << ans << endl;
		ans = 0;
	}

}

C++: #include <cstdio>
#include<iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <string.h>
#include<vector>
#include <set>
#include <vector>
#include <iterator>
using namespace std;
typedef long long int ll;
const int MAX_N = 999999 + 5;

int prime[MAX_N + 1];
int is_prime[MAX_N + 1];
void 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])
        {
            //cout << "**" << endl;
            prime[i] = ++p;
            for (int j = 2 * i; j <=  n; j += i)
                is_prime[j] = false;
        }
        else prime[i] = p;
    }
    return ;
}
int main()
{
    int a;
    sieve(999999);
    while (~scanf("%d", &a))
    {
        printf("%d\n", prime[a]);
    }
    return 0;
}

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

using namespace std;

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

int countPrime(int x, vector<int> &plist)
{
	int count = 0;
	for (int i = 2; i <= x; i++)
	{
		if (plist[i] == 0) continue;
		if (isPrime(i))
		{
			count++;
		}
		else
		{
			for (int j = i; j < x; j += i)
			{
				plist[j] = 0;
			}
		}
	}
	return count;
}

int main()
{
	int n;
	vector<int> plist(1000000, 1);
	while (cin >> n, !cin.eof())
	{

		cout << countPrime(n, plist) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int n, i, cnt, num[999999];

bool is_prime(int k)
{
	if(k == 1)  return false;
	if(k == 2)  return true;
	for(int i = 2; i*i <= k; i++){
		if(k%i == 0)  return false;
	}
	return true;
}

int count_prime()
{
	for(i = 1; i <= 999999; i++){
		if(is_prime(i))  cnt++;
		num[i] = cnt;
	}
	return 0;
}

int main()
{
	count_prime();
	while(scanf("%d", &n) != EOF){
		printf("%d\n", num[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  vector<int> v;
  v.resize(999999);
  fill(v.begin(), v.end(), 1);
  v[0] = 0;
  v[1] = 0;
  for (int i = 0; i * i < v.size(); ++i) {
    while (v[i] == 0) ++i;
    for (int m = i + 1; m < v.size(); ++m) {
      if (m % i == 0) {
        v[m] = 0;
      }
    }
  }
  while (cin >> n) {
      cout << accumulate(v.begin(), v.end() - (v.size() - (n + 1)), 0) << endl;
  }
  return 0;
}

C++: //AOJ0009
//20170415
//????????°??\???????´???°?????°

#include <iostream>

using namespace std;

int main()
{
  int n;
  do {
    cin >> n;
  } while (n < 1 || 999999 < n); //n???????????\???
  
  int a[n];
  for (int i = 0; i < n; i++)
    a[i] = i + 1; //??°??¨?????\???(1~n?????§)

  for (int i = 0; i < n; i++) { //????????°?????????
    int q = i + 1;
    if (i != 0 && a[i] != 0) { //1??§???????????¨?????????????????????????????°??§???????????¨?????????
      for (int j = q; j < n; j++) {
	if (a[j] != 0) { //????????\???????´???°??§????????????????????°?????????
	  int r = a[j] % q;
	  if (r == 0)
	    a[j] = 0; //??????q??§??????????????????0?????£??\??????
	}
	else
	  continue;
      }
    }
    else
      continue;
  } //??¨????????????????????????

  int b = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != 0)
      b++; //n??\???????´???°????????????????????????

  /*
  for (int i = 0; i < n; i++)
    cout << a[i] << " ";
  cout << '\n';
  */
  
  cout << b - 1 << '\n'; //??????
}

C++: #include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
bool prime[1000001];

typedef long long LL;
int main(){
        REP(i,1000001){
            prime[i]=true;
        }
        prime[0]=false;
        prime[1]=false;
        REP(i,1000001){
            if(prime[i]==false)continue;
            for(int j=2*i;j<1000001;j+=i){
                prime[j]=false;
            }
        }
        LL a;
        while(cin>>a){
           LL c=0;
           REP(i,a+1){
               if(prime[i]==true){
                  c++;
               }
           }
           cout<<c<<endl;
        }
	return(0);
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int ans=0,math[1000000]={0};
    math[1]=1;
    for(int i=2;i<n+1;i++){
      int bell=i;
      if(math[i]==0){
	ans++;
	math[i]=1;
      }
      while(bell<=n){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      } 
    }
    cout << ans << endl;
  }
}

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

int main(){
	while(1){
		int ans=0;
		int n;
		cin>>n;
		if(cin.eof())break;
		if(n==1){
			cout<<0<<endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5){
				for(int i=5;i<=n;i+=2){
				    if(i%3!=0){
				        bool prime=true;
					    for(int k=2;k<=sqrt(i);k++){
						    if(i%k==0){
							    prime=false;
							    break;
    						}
					    }
					    if(prime)ans++;
				    }
				}
			}
		cout<<ans<<endl;
		}
	}
}