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>
#include<cstdio>
using namespace std;
const int maxn=1e6+5,maxm=1e5+5;
int fac[maxn],pri[maxm],siz;
int a[maxn];
void euler(){
	int i,j;
	siz=0;
	for (i=0;i<maxn;i++) fac[i]=i;
	for (i=2;i<maxn;i++){
		if (fac[i]==i) pri[siz++]=i;
		for (j=0;j<siz&&pri[j]<=fac[i]&&i*pri[j]<maxn;j++)
			fac[i*pri[j]]=pri[j];
	}
}
int main(){
	int i,n;
	euler();
	a[0]=a[1]=0;
	for (i=2;i<maxn;i++)
		a[i]=a[i-1]+(fac[i]==i);
	while (scanf("%d",&n)!=EOF)
		printf("%d\n",a[n]);
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(cin >> n){
        bool prime[1000000] = {false};
        prime[1] = true;
        prime[2] = false;
        int count = 0;
      
        for(int j = 2; j * j <= n ; j++){
            if(!prime[j]){
                for (int k = 2; k*j <= n;k++){
                   prime[j*k] = true;
                }
            }
        }
        for(int i = 1;i<=n;i++){
            if(!prime[i]) count = count +1;
        }
        cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define MAX_N 100000

void q9() {
	bool IsPrime[MAX_N];
	memset(IsPrime, 1, sizeof(IsPrime));
	IsPrime[0] = false;
	IsPrime[1] = false;
	for (int i = 0; i < sqrt(MAX_N); i++) {
		if (!IsPrime[i]) continue;
		for (int j = i * 2; j < MAX_N; j += i) {
			IsPrime[j] = false;
		}
	}

	int NofP[MAX_N];
	NofP[0] = 0;
	for (int i = 1; i < MAX_N; i++) {
		NofP[i] = NofP[i - 1] + IsPrime[i];
	}

	int n;
	for (; cin >> n;) {
		cout << NofP[n] << endl;
	}
}

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

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

int main(){
        int prime[999999];
        bool is_prime[1000000];
        int p =0;
        int n ;
        int i;
        while(cin >> n){
        for(i=0;i<=n;i++) is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        for(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;
                }
        }
        cout << p << endl;
        p = 0;
        }
return 0;
}

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

int main(){
int n;
vector<int> a;
  while(cin < n){
  a.push_back(n);
  }
for(int i=0;i<a.size();i++){
  int k = 0;
  for(int j=2;j<a[i];j++){
    if(a[i]%j == 0 ) k++;
	}
  cout << k ;
 }
}

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

const int N = 1000000;
int data[1000000];
int n;

void Eratosthenes(){
  for(int i=0; i<N; i++){
    data[i] = 1;
  }
  for(int i=2; i<sqrt(N); i++){
    if(data[i]){
      for(int j=0; i*(j+2)<N; j++){
	data[i *(j + 2)] = 0;
      }
    }
  }
}

int main()
{
  int cnt = 0;
  Eratosthenes();
  while( cin >> n ) {
    cnt = 0;
    for(int i=2; i<=n; i++) {
      if( data[i] ) cnt++;
    }

    cout << cnt << endl;
  }
}

C++: #include<iostream>

int n;
int p;
int prime[1000000];
bool isprime[1000000];

void sieve()
{
	p = 0;
	isprime[0] = isprime[1] = false;
	for( int i = 2; i <= n; i++ ) isprime[i] = true;
	
	for( int i = 2; i <= n; i++ ){
		if( isprime[i] ){
			isprime[i] = false;
			prime[p++] = i;
			for( int j = i * 2; j <= n; j += i ) isprime[j] = false;
		}
	}

 	return;
}

int main()
{
	while( std::cin >> n ){	
		sieve();
		std::cout << p << std::endl;
	}

 	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define pb(a) push_back(a) 
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
 
int main() {
    int n = 1000000;
    vector<int> v;
    v.pb(2);
    for(int i=3;i<=n;i+=2) {
        bool add = true;
        rep(j,0,v.size()) {
            if(v[j] * v[j] > i) break;
            if(i % v[j] == 0) {
                add = false; 
                break;
            }
        }
        if(add) v.pb(i);
    }

    int m;
    while(cin >> m) {
        cout << upper_bound(v.begin(), v.end(), m) - v.begin() << endl;
    }
    return 0;
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

using namespace std;

int main()
{
    int n;

    while (cin>>n){
        int count=0;

        if(1<n){
            count++;
        }
        if(n%2==0){
            n--;
        }
        while (1 < n){
            int prime_flag=1;
            for (int j = 2; prime_flag && j < n; j++) {
                if(n % j == 0){
                    prime_flag=0;
                }
                if(2 < j){
                    j++;
                }
            }
            count+=prime_flag;
            n-=2;
        }
        cout<<count<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int count=0;
		for(int i=5;i<=n;i+=6){
			int j=5;
			while(true){
				if(i%j==0)
					break;
				if(j>(int)sqrt((double)i)){
					count++;
					break;
				}
				j+=2;
			}
		}
		for(int i=7;i<=n;i+=6){
			int j=5;
			while(true){
				if(i%j==0)
					break;
				if(j>(int)sqrt((double)i)){
					count++;
					break;
				}
				j+=2;
			}
		}
		cout<<count+1<<endl;
	}
	return 0;
}

C++: import java.util.Scanner;
import java.io.*;
class Main{
    public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int ans,n;
    while(sc.hasNext()){
    	n=sc.nextInt();
    	ans=0;
    	if(n==1)ans=-1;
    	for(int i=1;i<=n;i+=2){
    		int flag=0;
    		for(int j=3;j<=Math.sqrt(i);j+=2){
    			if(i%j==0){
    				flag=1;break;
    			}
    		}
    		if(flag==0)ans++;
    	}
    	System.out.println(ans);
    }
    }
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int max[30], sol[30], listID=0;
	
    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        min = 1;
        minID = 0;
		printf("check %d ->", n);
        for (int i=0; i<listID; i++){
            if (max[i] < n && min <max[i]){
                min = max[i];
				cnt = sol[i];
            }
        }
		printf("check  %d - %d (cur sols = %d)\n", min+1, n, cnt);
        for (int i=min+1; i<=n; i++){
            if (IsPrime(i)) cnt++;
        }
        max[listID] = n;
        sol[listID] = cnt;
        listID++;
        printf("%d\n", cnt);
    }
    return 0;
}

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

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			if(isprime(i))c++;

		}
		printf("%d\n",c);
	}
	return 0;
}