Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

using namespace std;

vector<bool> prime(1000010, 1);

signed main(){
    prime[0] = 0; prime[1] = 0; prime[2] = ( const ) 1;
    int ret = 0;
    int n; scanf( "%d", &n );
    for( int i = 2; i * i <= n; i++ ){
        if( prime[i] ){
            for( int j = 1; ( j + 1 ) * i <= n; j++ ){
                prime[i * ( j + 1 )] = 0;
            }
        }
    }
    for( int i = 0; i <= n; i++ )
    {
        if( prime[i] )
        {
            ret++;
        }
    }
    printf( "%d\n", ret );
    return 0;
}

C++: #include <iostream>
using namespace std;
int n;
#define MAX_N 1000000

int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // 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;
}

main() {
    sieve(MAX_N);
    while(cin>>n) {
        int ans=0;
        for(int i=2;i<=n;i++) {
            if(is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

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

static bool prime[MAX_N];
 static int num[MAX_N] = { 0 };

void ini()
{
	for (int i = 2; i < MAX_N; i++)
		prime[i] = true;
	for (int i = 2; i < MAX_N; i++)
	{
		if (!prime[i])
		{
			num[i] = num[i - 1] + prime[i];
			continue;
		}
		else
		{
			for (int j = i * 2; j < MAX_N; j += i)
			{
				if (prime[j] && j%i == 0)
					prime[j] = false;
			}
		}
		num[i] = num[i - 1] + prime[i];
	}
}

void solve()
{
	int n;
	while (cin >> n)
		cout << num[n] << endl;
}

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

C++: #include <cstdio>
int d[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i])continue;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	for(i=2;i<=999999;i++) {
		if(!d[i])r++;
		d[i]=r;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",d[n]);
	}
}

C++: #include<iostream>
int main(){
	for(int m,n,p;!(std::cin>>n).eof();){
		if(n<3)
			p=!(n-2);
		else for(m=3,p=1;m<=n;m+=2){
			p++;
			if(m<2)
				p--;
			else{
				for(int i=3;i*i<=m;i+=2)
					if(m%i==0){p--;break;}
			}
		}
		printf("%d\n",p);
	}
}

C++: 
def generate (n)
    $P = Array.new(n, false)
    i = 3
    until i > n
        $P[i] = true
        i += 2
    end
    i = 3
    $P[2] = true
    until i > n
        if ! $P[i]
            i += 2
            next
        end
        j = i + i
        until j > n do
            $P[j] = false
            j += i
        end
        i += 2
    end
end

def is_prime (n)
    return $P[n] ? 1 : 0
end

def solve (n)
    return ->() {
        res = 0
        (n+1).times {|v| res += is_prime(v) }
        res
    }.call
end

generate 1000000 
while s = gets do
    n = s.to_i
    p solve n
end

C++: #include<stdio.h>

int main(void)
{
	int d=2,i,j,s[10000],x;

	while((scanf("%d",d))!=EOF)
	{
		for(i=0;i<=d;i++){
			s[i]=1;}
		x=0;
		if(d<=1){
			printf("%d\n",0);
		}
		else
		{
			for(i=2;i<=d/2;i++)
			{
			  if(s[i]!=0)
			  {
				for(j=i*2;j<d;j+=i)
				    s[j]=0;
			  }
			}
		for(i=0;i<=d;i++)
			x+=s[i];
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include<iostream>
using namespace std;
#define N 1000000
bool p[1000000];
int main(){
  int n;

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

  for(int i=0;i<=N/2;i++)
    if(p[i]==true)
      for(int j=i*2;j<N;j+=i)
	p[j]=false;

  while(cin>>n){
    int count=0;
    for(int i=0;i<=n;i++)
      if(p[i]==true)count++;
    cout<<count<<endl;
  }
  return 0;
}

C++: /*
http://blog.csdn.net/liuke19950717
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef int ll;
const int maxn= 999999+5;
ll prime[maxn];
int main()
{
	ll cnt=0;
	for(ll i=2;i<maxn;++i)
	{
		if(!prime[i])
		{
			prime[i]=++cnt;
			for(ll j=i*i;j<maxn;j+=i)
			{
				prime[j]=1;
			}
		}
		else
		{
			prime[i]=prime[i-1];
		}
	}
	ll n;
	while(~scanf("%lld",&n))
	{
		printf("%lld\n",prime[n]);
	}
	return 0;
}

C++: #include <stdio.h>

void cnt(int i) {
	int j,k,l,m;
	l=0;
	m=0;
	for(j=1;j<=i;j++){
		for(k=1;k<=j;k++){
			if(j%k == 0){
				l++;
			}
		}
		if(l == 2){
			m++;
		}
		l=0;
	}
	printf("%d\n",m);
}

int main(void){
	int i;
	while (scanf("%d", &i) != EOF){
		cnt(i);
	}
}

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

int main()
{
	int n[30];
	int i=0;
	while(cin >> n[i]) {i++;}
		
	for (int k=0;k<i;k++){
		int s=1;
		for (int j=3;j<=n[k];j++){
			for(int m=2;m<j;m++){
				if(j%m==0){break;}
				if(m==j-1){s=s+1;}
			}
		}
		cout << s << endl;
	}	
    return 0;
}

C++: #include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=999999+5;
int prime[maxn];
bool is_prime[maxn];
int sieve(int n)
{
    int p=0;
    fill(is_prime,is_prime+n+1,true);
    is_prime[0]=is_prime[1]=true;
    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 n;
    while(cin>>n)
    {
        cout<<sieve(n)<<endl;
    }
    return 0;
}

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

#define add push_back
#define inf 2147000000

#define rep(i,n) for(int i=0;i<n;i++)
#define out(a) cout<<a<<endl;

using namespace std;

int main(void){
	int sosuu[100000];
	int cont=0;
	int n;
	scanf("%d",&n);
	
	for(int i=2;i<=n;i++){
		for(int j=0;;j++){
			if(j==cont){
				sosuu[cont]=i;
				cont++;
				break;
			}
			if(i%sosuu[j]==0){
				break;
			}
		}
	}
	out(cont);
}

C++: #include <stdio.h>

bool isPrime(int n);

int main(void){
    int n;
    int primes;
    
    while (scanf("%d", &n)!=EOF){
        primes = 0;
        for (int i=2; i<=n; i++){
            if (isPrime(i)) primes++;
        }
        printf("%d\n", primes);
    }
}

bool isPrime(int n){
    if (n==1) return false;
    for (int t=2; t*t<=n; t++){
        if (n%t == 0) return false;
    }
    return true;
}

C++: #include"iostream"

using namespace std;
int sum;
int prime(int n) {
	if (n > 2 && !(n & 1) || n < 2)
		return 0;
	for (int i = 3; i*i <= n; i += 2)
		if (!(n%i))
			return 0;
	sum++;
	return 0;
}

int main()
{
	int n,t=1;
	int *p;
	while (cin >> n)
	{
		sum = 0;
		p = new int[n];
		for (int i = 1; i <= n; i++)
			p[i] = prime(i);
		cout << sum << endl;
		t++;
		if (t > 30)
			break;
	}
	return 0;
}

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

int main() {
	int N;
	while(cin >> N){
		int is_prime[N+1];
		is_prime[0]=0; is_prime[1]=0;
		for(int i=2;i<N+1; i++){
			is_prime[i]=1;
		}
		
		for(int s=2; s<N+1; s++){
		
		if(is_prime[s]==1){	
		for(int i=s*s; i<N+1; i+=s){
			is_prime[i]=0;
		}
}
		
		}
		int ans=0;
		for(int i=2; i<N+1; i++){
			ans+=is_prime[i];
		}
		cout << ans <<endl;
		
	}
	return 0;
}

C++: #include<stdio.h>
main(){
	int i,j,n,p[1000000];
	scanf("%d",&n);
	for(i=2;i<=n;i++)
		p[i]=1;
	for(i=2;i<n;i++)
		for(j=2;i*j<=n;j++)
			p[i*j]=0;
	j=0;
	for(i=2;i<n;i++)
		j+=p[i];
	printf("%d\n",j);
}