Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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

int prime[MAX_N];
bool is_prime[MAX_N + 1];
int sieve(int n){
	int p = 0;
	fill(is_prime, is_prime + n + 1, 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 = i * 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>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=2;j<=n;j++){
			k=0;
			for(int i=2;i<=j;i++){
				if(j%i==0)k++;
		        }
		     if(k==1)kk++;
		   }
		cout<<kk<<endl;
	   }
	return 0;
	}

C++: #include<iostream>
using namespace std;
int main(){
int n,ans,i,j;
while(cin>>n){
	ans=0;
	for(i=2;i<=n;i++){//search for 2 to n
		for(j=2;j<=i;j++){//judge the number
			if(i%j==0)break;
		}
		if(j==i){
			cout<<i<<endl;
			ans++;
		}
	}
	cout<<ans<<endl;
}
return 0;
}

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

int main()
{
	int counter=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<'0'<<endl;
			break;
		}

		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				counter++;
		}
		cout<<counter<<endl;
		counter=1;
	}
}

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

int main(){
bool unti[1000000];
fill(unti,unti+1000000,0);
for(int n = 2;n < 1000000;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 1000000;a++)
{
	unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
	}
return 0;
}

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

int main()
{
	int count=1,n,flag;
	
	while(scanf("%d",&n))
	{
		if(n<=1) 
		{
			cout<<0<<endl;
		}

		else{
		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				count++;
		}
		printf("%d\n",count);
		count=1;}
	}
}

C++: #include<stdio.h>
int main ()
{
    int n,i,m,sum;
    while(1)
    {
        sum=0;
        scanf("%d",&n);
        for(m=2;m<=n;m++)
        {
            for(i=2;i<=m;i++)
            {
                if(m%i==0 && i<m)
                {
                    break;
                }
                if(i==m)
                {
                    sum=sum+1;
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n;
	int count = 1;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
	}
	else if (n == 2) {
		cout << 1 << endl;
	}
	else {
		for (int t = 3; t <= n; t += 2) {
			FOR(i, 2, t - 1) {
				if (t%i == 0) {
					break;
				}
				if (i == t - 1) {
					count++;
					break;
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

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

int main(){
int n;
cin >> n;
int a[n+1];
int b;
int c;
b=1;
while(b<n+1){
a[b]=0;
b=b+1;}
a[1]=1;
b=2;
while(b<n+1){
if(a[b]=0){ c=2; while(1){if(c*b>n){break;} a[c*b]=1; c=c+1;}}
b=b+1;}

int d;
d=0;
b=1;
while(b<n+1){
if(a[b]=0){d=d+1;}
b=b+1;}
cout << d;


}

C++: 
/* vo00_09.cpp */

#include <iostream>
using namespace std;

const int N = 1000000;
int prime[N];

void init();

int main()
{
	init();

	int n;
	while (cin >> n) {
		
		cout << prime[n] << '\n';

	}

	return 0;
}

void init()
{
	prime[0] = prime[1] = -1;

	int count = 0;
	for (int i = 2; i < N; ++i) {
		if (prime[i] == 0) {
			for (int j = i * 2; j < N; j += i) { prime[j] = -1; }
			count++;
		}
		
		prime[i] = count;
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())


int mem[1000000];
int ans[1000000];

int main(int argc, char const *argv[])
{
	int max_num = 1000000;
	int loop_max = sqrt(1000000);
	memset(mem, 0, 1000000);
	for (int i = 2; i < loop_max; i++)
	{
		int c = i * 2;
		while(c < max_num)
		{
			mem[c] = 1;
			c+= i;
		}
	}
	int n;
	int sum = 0;
	ans[0] = ans[1] = 0;
	for (int i = 2; i < max_num; i++)
	{
		sum += mem[i] ? 0 : 1;
		ans[i] = sum;
	}
	while(scanf("%d", &n) != EOF)
	{
		printf("%d\n", ans[n]);
	}
	return 0;
}

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

using namespace std;

int main(){
	int n,i,j,buf,cnt;

	scanf("%d",&n);

	while(n != EOF){
		cnt = 1;

		for(i=3;i<=n;i+=2){
			buf = (int)sqrt((double)i);

			for(j=3;j<=buf;j+=2){
				if((i % j) == 0){
					cnt--;
					break;
				}
			}

			cnt++;
		}

		printf("%d\n",cnt);

		scanf("%d",&n);
	}

	return 0;
}

C++: //============================================================================
// Name        : desk.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<stdio.h>
#include<iostream>
using namespace std;
int main(){

 int n=0,f=0,P=0;

 while(scanf("%d",&n)!=EOF){

 for(int i=2;i<n;i++){

	 if(n%i==0){
		f=1;
		}

 }

 if(f==0){
	 P++;
 }
 cout<<P<<endl;
 }

  return 0;
}

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

int main(){
	int n,t;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			int j=3;
			t=1;
			while( j <= sqrt(i) ){
				if(i%j==0){
					t=0;
				}
				j+=2;
			}
			if(t){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=1e7;
int is_prime[MAXN],prime[10000];
int sieve(int n){
	memset(is_prime,-1,sizeof(is_prime));
	int index=0;
	prime[0]=prime[1]=0;
	for(int i=2;i<=n;i++){
		if(is_prime[i])prime[index++]=i;
		for(int j=2*i;j<=n;j+=i)
		is_prime[j]=0;
	}
	return index;
}
int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",sieve(n));
	}
	return 0;
}

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

bool isPrimeNumber(int number){
	if(number	  == 2)	return true;
	if(number % 2 == 0)	return false;
	
	for(int i = 3; i <= sqrt(number) ;i += 2){
		if(number % i == 0)	return false;
	}
	
	return true;
}

int main(int argc, char** argv){
	
	int search, counter;
	
	while((scanf("%d", &search)) != EOF){
		counter = 0;
		for(int i = 2; i <= search; i++){
			counter += isPrimeNumber(i) ? 1 : 0;		
		}
		printf("%d\n", counter);
	}
	
	return 0;
}