Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std; 

int list[1000000]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757,
 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil,input,mid;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	lo=1087;
	a=180;
	while(lo<=1000003)
	{
		if(Prima(lo))
		{
			list[a]=lo;
			a++;
		}
		lo+=2;
	}
	//printf("%d",list[78498]);
	//while(scanf("%ld",&input)!= EOF)
	{	
	lo=0;
	while(input>=list[lo])
	{
		lo++;
	}
	printf("%d\n",lo);
	}
	return 0; 
}

C++: import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			if(!sc.hasNext())
				break;
			int n=sc.nextInt();
			int a=0;
			for(int i=2; i<=n; i++)
				if(isPrime(i))
					a++;
			println(""+a);
		}
		sc.close();
	}

	boolean isPrime(int n){
		int m=(int)sqrt(n);
		if(n==2)
			return true;
		if(n%2==0)
			return false;
		for(int i=3; i<=m; i++)
			if(n%i==0)
				return false;
		return true;
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

C++: /*
题意：给定整数 n， 请问 n 以内有多少个素数？
思路：如果对许多整数进行素性测试，则采用 埃氏筛法 （枚举 n 以内的素数，辗转相除）
		埃氏筛法：辗转相除：
			首先，将 2 到 n 范围内的所有整数写下来。其中最小的数字 2 是素数。将表中所有 2 的倍数都划去。
			表中剩余的最小数字是 3，它不能被更小的数整除，所以是素数。再将表中所有 3 的倍数都划去。
			以此类推，如果表中剩余的最小数字是 m 时，m就是素数。然后将表中所有 m 的倍数都划去。 
			像这样反复操作，就能依次枚举 n 以内的素数。 
*/

#include <iostream>
#include <stdio.h>
using namespace std;
#define MAX_N  1000

int prime[MAX_N];		// 第 i 个素数 
bool is_prime[MAX_N];	// is_prime[i] 为 true 表示 i 为素数 

// 返回 n 以内素数的个数 
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 s;
//	while (cin  >>  s)
	while (scanf("%d", &s) != EOF) 
	{
		cout << sieve(s) << endl;
	}	
	return 0;
}

C++: #include<iostream>
#include<math.h>
#define MAX 1000000
using namespace std;
int main(){
	bool p[MAX+1];
	int n,count;
	for(int i=2; i<=MAX; i++)
		p[i] = true;
	for(int i=2; i<=sqrt(MAX); i++){
		if(p[i] == true){
			for(int j=2*i; j<=MAX; j++){
				if(j%i == 0)
					p[j] = false;
			}
		}
	}
	while(cin >> n){
		count = 0;
		for(int i=0; i<=n; i++){
			if(p[i] == true)
				count++;
		}
		cout << count << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;


using namespace std;
bool priN[1000000]={};
bool pri[1000000]={};

bool isPrime(int n){
	if(priN[n]==true)return pri[n];
	for(int i=3;i<=sqrt((double)n);i++){
		if(n%i==0){
			priN[n]=true;
			pri[n]=false;
			return false;
		}
	}
	priN[n]=true;
	pri[n]=true;
	return true;
}

int main(){
	while(1){
		int n;
		if( !(cin>>n) )break;
		ll sum=1;
		for(int i=3;i<=n;i+=2){
			if(isPrime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

int eratosthenes(int n, vector<bool>& prime) {
    int ret = 0; prime.assign(n, false);
    vector<bool> chk(n, false);
    for (auto i = 2; i < n; i++) {
        if(chk[i]) continue;
        ret++; prime[i] = true;
        for (auto j = i; j < n; j += i) chk[j] = true;
    }
    return ret;
}

int main(){
    vector<bool> prime; eratosthenes(1000000, prime);
    vector<int> cnt(1000000, 0);
    for (auto i = 0; i < 1000000; i++) {
        if(prime[i]) cnt[i]++;
        cnt[i + 1] += cnt[i];
    }

    string s;
    while(cin >> s){
        int n = stoi(s);
        cout << cnt[n] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=n; i>1; i--){
			if(i == 2){
				ans++;
			}else{
				bool isPrime = true;
				for(int j=2; j<=i/2; j++){
					if(i % j == 0){
						isPrime = false;
						break;
					}
				}
				if(isPrime)
					ans++;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include<queue>
#include<stack>
#include<cstdio>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int ans=n-1;
		int d[999999+100]={};
		for(int i=2;i<=n;i++){
			for(int j=3;j<=n;j++){
				if(d[j]==0 && j%i==0 && j!=i){
					d[j]=1;
					ans--;
				}
			}
		}
		cout<<ans<<endl;
	}
		return 0;
}

C++: #include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

bool prime[1000000];
li sum[1000000];

int main(){
	rep(i,1e+6)prime[i]=true;
	prime[0]=prime[1]=false;
	
	repp(i,2,sqrt(1e+6)+1){
		for(li j=2; j*i<=1e+6; j++){
			prime[i*j]=false;
		}
	}
	
	sum[0]=0;
	repp(i,1,1e+6)sum[i]=sum[i-1]+(prime[i]?1:0);
	
	li n;
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	
	return 0;
}

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

bool is_prime(int n,int r);

int main(void) {
	using namespace std;
	int x;
	int count;

	while (cin >> x) {
		count = 0;
		double r = pow(x, 0.5);
		for (int i = 2; i <= x; i++) {
			if (is_prime(i,r))count++;
		}
		cout << count << endl;
	}
	return 0;
}



bool is_prime(int n,int r) {
	static int flag = 0;
	static int list[78498];
	static int count = 0;
	if (flag == 1) {
		for (int i = 0; i < count; i++) { 
			if (list[i] >r) {
				return true;
			}
			if (n % list[i] == 0) {
				if (n == list[i]) {
					
					return true;
				}
				
				return false;
			}
		}

	}
	flag = 1;
	list[count] = n;		
	count++;
	
	return true;
}