Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

class Sieve_of_Eratosthenes {
public:
	vector<bool> PN;
	
	Sieve_of_Eratosthenes(int x){
		init(x);
	}
	
	void huga(int t, int x){
		if(PN[t]) return;
		for(int i = t*t; i <= x; i+=t)
			PN[i] = true;
	}
	
	void init(int x){
		PN.resize(x+5);
		PN[0]=PN[1]=PN[4]=true;
		for(int i = 6; (i-1)*(i-1) <= x; i+=6)
		huga(i-1,x),huga(i+1,x);
		for(int i = 6; i <= x; i+=6)
			PN[i]=PN[i+2]=PN[i+3]=PN[i+4]=true;
	}
};

int main(){
	const int MAX = 1000000;
	int n;
	
	Sieve_of_Eratosthenes S(MAX);
	vector<int> sum(MAX);
	
	for(int i = 1; i < MAX; i++){
		sum[i] += sum[i-1] + !S.PN[i];
	}
	
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	return 0;
}

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

int main(){
	int num, cou, i, j, flag;
	
	while(cin >>num){
		cou = 0;
		for(i = 2; i <= num; i++, flag = 0){
			for(j = 2; j < i; j++){
				if(i % j == 0){
					flag = 1;
					break;
				}
			}
			if(flag == 0){
				cou++;
			}
		}
		if(num % 2 == 0) cou++;
		cout <<cou<<endl;
	}
	
	return 0;
}

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

int main()
{
	unsigned int  n;
	cin >> n;
	unsigned  int num,count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(int j = 2; j <=num; j++)
		{
			if(num == j)count++;
			if((num % j) == 0)
			{
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
typedef long long LL;
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
const int N=1e7;
int sum[N],vis[N];
void initPrime()
{
    int num = 0, m = sqrt (N + 0.5);
    for (int i = 2; i <= m; ++i)
        if (vis[i] == 0)
            for (int j = i * i; j <= N; j += i) vis[j] = 1;
    sum[1]=0;
    for(int i=2;i<=N;i++)
    {
        if(!vis[i])  sum[i]=sum[i-1]+1;
        else   sum[i]=sum[i-1];
    }
//    for(int i=2;i<=10;i++)
//        cout<<"233  "<<sum[i]<<endl;
}
int main()
{
    int n;
    initPrime();
    while(~scanf("%d",&n))
        printf("%d\n",sum[n]);
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	unsigned int  n;
	cin >> n;
	unsigned int num, count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(int j = 2; j <=num; j++)
		{
			if(num == j)count++;
			if(num % j == 0)
			{
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
bool b[999999+1];

int main() {
	for (int i = 2; i < 999999 + 1; i++){
		if (b[i] == false){
			for (int j = i * 2; j < 999999 + 1;j+=i){
				b[j] = true;
			}
		}
	}
	int n;
	while (cin >> n){
		int count = 0;
		for (int i = 2; i <= n; i++)if (!b[i])count++;
		cout << count << endl;
	}
}

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

int arr[123456];

int main()
{

    int n;
    while(scanf("%d",&n)==1){
            memset(arr,0,sizeof arr);
    int k=0;
    int s=sqrt(n+1);

    for(int i=4;i<=n;i=i+2)
    {
        arr[i]=1;
    }
    for(int i=3;i<=s;i++)
    {
        if(arr[i]==0)
        {
            for(int j=i*i;j<=n;j=j+i)
            {
                arr[j]=1;
            }
        }
    }

    for(int i=2;i<=n;i++)
    {
        if(arr[i]==0)
        {
            k++;
        }
    }
    cout<<k<<endl;

    }


    return 0;
}

C++: #include<iostream>



using namespace std;



int n;

int prime[1000000];

int checked[1000000];

int primesum[1000000];

int result[30];

int datasets;



int main()

{

	prime[0] = 0;

	prime[1] = 0;

	primesum[0] = 0;

	primesum[1] = 0;



	for (int a = 2; a<1000000; a++)

	{

		prime[a] = 1;

	}



	for (int a = 2; a<1001; a++)

	{

		if (checked[a] == 0)

		{

			checked[a] = 1;

			for (int b = 2; b<a; b++)

			{

				if (a%b == 0)

				{

					prime[a] = 0;

					break;

				}

			}

			if (prime[a] == 1)

			{

				for (int c = 2 * a; c<1000000; c += a)

				{

					checked[c] = 1;

					prime[c] = 0;

				}

			}

		}

	}



	for (int a = 2; a<1000000; a++)

	{

		primesum[a] = primesum[a - 1] + prime[a];

	}



	while (cin >> n)

	{

		cout << primesum[n] << endl;

	}



	return 0;

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int p[MAX];
void f(){
	int n=0;
	for(int i=2;i<MAX;i++){
		if(p[i]==0){
			p[i] = ++n;
			for(int j=2;j*i<MAX;j++)
				p[j*i] = -1;
		}
		else p[i] = n;
	}
} 
int main(){
	int n;
	f();
	while(cin>>n){	
		cout<<p[n]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define nINF -2147483648
using namespace std;
int p10(int x)
{
	int t=1;
	for (int i=1;i<=x;i++) t*=10;
	return t; 
}

bool a[1000000];
int s[1000000];
int main()
{
	int k,t=0;
	for (int i=2;i<=p10(3);i++)
	{
		k=2;
		while (i*k<p10(6))
		{
			a[k*i]=true;
			k++;
		}
	}
	for (int i=2;i<=p10(6);i++)
	{
		if (!a[i]) t++;
		s[i]=t;
	}
	while (cin>>k) cout<<s[k]<<endl;
	return 0;
}

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

#define MAX 1000000

int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}
	primes[2] = true;
	
	int n;
	while ( cin >> n )
	{
		int cnt = 0;
		for ( int i = 0; i <= n; ++i )
		{
			if ( primes[i] )
				cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

C++: import sys
import math as mas

def sieve(n):
	p=[True for i in range(n+1)]
	p[0]=p[1]=False
	end=int(n**0.5)
	for i in range(2,end+1):
		if p[i]:
			for j in range(i*i,n+1,i):
				p[j]=False
	return p
	
sosu=sieve(1000010)
for i in sys.stdin:
	t=int(i)
	if t<2:print(0)
	elif t==2:print(1)
	else:print(1+sum(sosu[t] for t in range(3,int(i)+1,2)))

#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))