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<iostream>
using namespace std;
int a[1000000];
int sum[1000000];
int n;
int main(){
 for (int i=2;i<1000000;i++){
  if (!a[i])
   for (int j=i*2;j<1000000;j+=i)
    a[j]=1;
 }
 for (int i=2;i<1000000;i++) sum[i]=sum[i-1]+(a[i]==0?1:0);
 while (cin>>n)
  cout<<sum[n]<<endl;
 return 0;
}

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

int main(){
  bool p[1000000];
  int num[1000000];
  int c,n;

  for(int i=0;i<1000000;i+=2)p[i] = false;
  for(int i=1;i<1000000;i+=2)p[i] = true;
  p[1] = false;
  p[2] = true;

  c = 3;
  while(c < 1000){
    for(int i=3*c;i<1000000;i+=2*c)p[i] = false;
    do{c+=2;}while(!p[c]);
  }

  c = 0;
  for(int i=0;i<1000000;i++){
    if(p[i])c++;
    num[i] = c;
  }

  while(cin >> n)cout << num[n];
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

bool prime(int p){
	if ((p==0)||(p==1)){return false;}
	else if(p==2){return true;}
	else{
		for(int i=2; i*i<=p; i++){
			if(p%i == 0){return false;}
		}
	}
	return true;
}

int main()
{
	int n;

	while(cin >> n){
		int count = 0;
		for(int i=0; i<n+1; i++){
			if(prime(i)){count++;}
		}

		cout << count << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

bool prime(int p){
	if ((p==0)||(p==1)){return false;}
	else if(p==2){return true;}
	else{
		for(int i=2; i*i<=p; i++){
			if(p%i == 0){return false;}
		}
	}
	return true;
}

int main()
{
	int n;

	while(cin >> n){
		int count = 0;
		if(n>2){count++;}
		for(int i=1; i<n+1; i=i+2){
			if(prime(i)){count++;}
		}

		cout << count << endl;
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

bool Is_Prime(int n){
  if(n==1) return false;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      return false;
    }
  }
  return true;
}
int p[100006];

signed main(){
  loop(i,2,100001){
    if(Is_Prime(i))p[i]=1;
  }
  rep(i,100001)p[i+1]+=p[i];
  int n;
  while(cin>>n){
    cout<<p[n]<<endl;
  }
  return 0;
}

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

using namespace std;

vector<int> Prime;
void PrimeCalc(int n)
{
	bool IsPrime[1000000];
	for(int i = 0; i < 1000000; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < 1000000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 1000000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	int n;
	cin >> n;
	PrimeCalc(n);
	int ans = 0;
	int pos = 0;
	for(int i = 0; i < Prime.size(); ++i)
	{
		if(Prime[i] <= n)
		{
			++ans;
		}
		else
		{
			break;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAX 10000
bool prime[MAX];
int main(void){ 

  fill(prime,prime+MAX,true);
  prime[0] = prime[1] = false;
  for(int i = 2 ; MAX > i * i ; i ++){
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  } 
  int n;
  while(cin>>n,n){
    if(n%2)cout<<"0"<<endl;
    else{
      int cnt = 0,sum = 0;
      for(int i = 0 ; i <= n/2 ; i ++){
	for(int j = i ; j < n ; j ++){
	  if(prime[i] && prime[j]){
	    if(i+j==n)cnt++;
	  } 
	}
      } 
      cout<<cnt<<endl;
    }
  }
}

C++: #include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

std::vector<std::size_t> prime_table = {2};

void make_prime_table()
{
    std::set<std::size_t> undefined_table;
    for(std::size_t i = 3; i <= 999999; i += 2)
    {
        undefined_table.insert(i);
    }

    const std::size_t sn = 1000;
    for(std::size_t p = 0; !undefined_table.empty() && p < prime_table.size(); ++p)
    {
        for(auto u = undefined_table.begin(); u != undefined_table.end();)
        {
            if(0 == *u % prime_table[p])
            {
                u = undefined_table.erase(u);
            }
            else
            {
                ++u;
            }
        }

        if(!undefined_table.empty())
        {            
            prime_table.push_back(*undefined_table.begin());
            undefined_table.erase(undefined_table.begin());
            if(sn <= prime_table.back())
            {
                break;
            }
        }
    }
    prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
}

std::array<std::size_t, 1000000> prime_acc = {{0, 0}};

void make_prime_acc()
{
    std::size_t acc_found = 1;
    for(auto p = prime_table.begin(); p != prime_table.end(); ++p)
    {
        std::fill_n(prime_acc.begin() + acc_found + 1, *p - acc_found - 1, prime_acc[acc_found]);
        acc_found = *p;
        prime_acc[acc_found] = prime_acc[acc_found - 1] + 1;
    }
    std::fill(prime_acc.begin() + acc_found + 1, prime_acc.end(), prime_acc[acc_found]);
}

int main()
{
    make_prime_table();
    make_prime_acc();

    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_acc[n] << std::endl;
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=sqrt(j);i+=2){
				if(j%i==0)k++;
		        }
		     if(k==1)kk++;
		   }
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<"1"<<endl;
		else cout<<kk+1<<endl;
	   }
	return 0;
	}

C++: #include<iostream>
using namespace std;
int prime[1200000];
int main(){
	for(int i=2;i<1200000;i++)prime[i]=1;
	for(int i=2;i*i<1200000;i++){
		for(int j=i*i;j<1200000;j+=i){
			prime[j]=0;
		}
	}
	for(int i=2;i<1200000;i++)prime[i]+=prime[i-1];
	int n;
	while(cin>>n){
		cout<<prime[n]<<endl;
	}
}

C++: #include <iostream>

using namespace std;

bool isPrime(int n){
	
	if (n == 1)
		return false;
	if (n == 2)
		return true;

	for (int i = 2; i*i <= n; ++i){
		if (n % i == 0)
			return false;
	}
	return true;
}

int main(){
	int n;

	while (cin >> n){
		int c = 0;
		for (int i = 1; i <= n;++i){
			if (isPrime(i))
				++c;
		}
		cout << c << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int i, j, n, isFound;
  vector<int> prime;

  while(cin >> n){
    for(i=2; i<=n; ++i){
      isFound = 1;
      for(j=0; j < prime.size(); ++j){
	if(i % prime[j] == 0){
	  isFound = 0;
	  break;
	}
      }
      if(isFound == 1)
	prime.push_back(i);
    }
    cout << prime.size() << endl;
    prime.clear();
  }

  return 0;
}

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

int num(int n)
{
    int a[1000000] = {1, 1};
    for (int i = 2; i <= n; ++i)
        for (int j = 2; i * j <= n; ++j)
            a[i * j] = 1;
    int cnt = 0;
    for (int i = 0; i <= n; ++i)
        if (a[i] == 0)
            ++cnt;
    return cnt;
}

int main(void)
{
    int n;
    while (cin >> n)
        cout << num(n) << endl;
    return 0;
}