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>
using namespace std;
const int MAX_V = 1000000; // 100????????§?´???°??¨?????????
const int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????? 
const 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 <cmath>
#include <iostream>

using namespace std;

bool prime_check(int n)
{
	if (n == 1)
	{
		return false;
	}
	else if (n == 2)
	{
		return true;
	}
	else
	{
		for (int i = 2; i <= sqrt(n); i++)
		{
			if (n % i == 0)
			{
				return false;
			}
		}
	}

	return true;
}

int main()
{
	// --- variable define --- //

	int n, c;


	// --- prime check ( 2 to 999 ) --- //

	bool isprime[1000];

	for (int i = 1; i < 1000; i++)
	{
		if (prime_check(i) == true)
		{
			isprime[i] = true;
		}
		else
		{
			isprime[i] = false;
		}
	}


	// --- main --- //

	while (cin >> n)
	{
		c = 0;

		for (int i = 2; i <= n; i++)
		{
			if (i <= 999)
			{
				if (isprime[i] == true)
				{
					c += 1;
				}
				else
				{
					c += 0;
				}
			}
			else
			{
				for (int j = 2; j <= sqrt(i); j++)
				{
					if (n % i == 0)
					{
						c += 0; goto Exit;
					}
				}

				c += 1;
			}
		Exit:;
		}

		cout << c << endl;
	}
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,z,x;
	
    scanf("%d",&n);
	for(n!=1){
		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 <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9


bool primes[1000000];

void make_prime(){
	for(int i=2; i<1000000; i++)primes[i]=true;
	for(int i=2; i*i<=1000000; i++)
		for(int j=i*2; j<1000000; j+=i)primes[j]=false;
}

int main(){
	int n,ret;
	make_prime();
	while(~scanf("%d",&n)){
		ret = 0;
		for(int i=2; i<=n; i++)if( primes[i] )ret++;
		printf("%d\n",ret);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]){
        for(int j =i*i;j<MAX;j+=i){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

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

const int m=500000;
int prime[m];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<m; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<m; j+=i) prime[j]=0;
    }
    for(int i=1; i<m; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}

C++: #include <stdio.h>

int main(){
    int n,in,count,i,j;
    char era[1000000];

    scanf("%d",&in);

    for(i=0;i<=in;i++){
        era[i]=1;
    }

    count=0;
    for(i=2;i<=in;i++){
        if(era[i] == 1){
            count++;
            for(j=i;j<=in;j+=i){
                era[j]=0;
            }
        }
    }
    printf("%d\n",count);

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef vector<int> VI;
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )

template<typename T>
T getPrimeNum(vector<bool> primes, T index) {
    T ret = 0;
    for (auto i = 0; i <= index; i++) {
        if (primes.at(i)) {
            ++ret;
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<bool> primes(1000000, true);
    primes[0] = false;
    primes[1] = false;
    for (unsigned long n = 2; n < 1000000; n++) {
        if (n*n > 1000000)    break;
        if (!n)    continue;
        for(unsigned long i = n+n; i < 1000000; i=i+n) {
            primes[i] = false;
        }
    }

    unsigned long input;
    vector<unsigned long> inputs;
    while (cin >> input) {
        inputs.push_back(input);
    }

    for (auto n : inputs) {
        cout << getPrimeNum(primes, n) << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool memo[1000002];

int main() {

  rep (i, 1000002) memo[i] = true;

  memo[0] = memo[1] = false;

  for (int k = 2; k < 1000002; ++k) {
    if (!memo[k]) continue;
    for (int i = k+k; i < 1000002; i += k) memo[i] = false;
  }

  for (int n; cin >> n, cin; ) {
    int ans = 0;
    rep (k, n+1) if (memo[k]) ++ans;
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,i,j;
    while(scanf("%d",&a)!=EOF){
        b=0;
        for(i=2;i<=a;i++){
            c=0;
            for(j=2;j*j<=i;j++){
                if(i%j==0){c++;break;}
            }
            if(i==2||i==3)c++;
            if(c==0)b++;
            if(i==2||i==3)b++;
        }
        cout<<b<<endl;
    }
    return 0;
}