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>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1000000+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        //int *p=upper_bound(prime,prime+num,n);
        //int ans=p-prime;
        //cout<<ans<<endl;
        int ans=0;
        for(int i=0;i<num;i++){
            if(prime[i]<=n)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
const int N = 1e7 + 1;
bool isprime[N];

void seive(){
  fill (isprime + 2, isprime + N, true);
  for(int i = 2; i < N; i ++){
	  if (isprime[i]){
		for(int j = 2 ; i * j < N; j++){
			 isprime[i * j] = false;
	      }  
	   }  
	}
}

void solve(){
	seive();
     int n;
     while(cin >> n){
	  int cnt = 0;
	  for(int i = 1; i <= n; i++)
	    cnt += (isprime[i]);
	  cout << cnt << endl;
  }
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[1000000];
    int n;
    cin>>n;
    a[0]=2;
    int k=1;
    
    for(int i=3;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;
    cout<<k<<endl;
}

C++: #include <cstdio>
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;scanf("%d", &n);n++){
  	printf("%d\n", npr[n]);
  }
  return 0;
}

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

class prime{
	int cnt;
	vector<int> p;
public:
	prime();
	int num(int n);
};

prime::prime(){
	p.clear();
}

int prime::num(int n){
	if(n<2)return 0;
	if(n==2)return 1;
	p.push_back(2);
	int c;
	cnt=1;
	for(int i=3;i<=n;i+=2){
		c=0;
		for(int j=0;j<(int)p.size();j++){
			if(i%p[j]==0){
				c++;
				break;
			}
		}
		if(c==0){
			p.push_back(i);
			cnt++;
		}
	}
	return cnt;
}

int main()
{
	int n;
	while(cin >> n){
		prime pr;
		cout << pr.num(n) << endl;
	}
	return 0;
}

C++: #include <stdio.h>
bool used[1000005];int RideBack[79000],last=0;
int bin_search(int val) {int left=0,right=last-1,ans=0;while (left<=right) {int center=(left+right)>>1;if (RideBack[center]>val) right=center-1;else left=center+1,ans=left;} return ans;}
int main() {
    int i;for (i=2;i<=1000000;used[i++]=true);
    for (i=2;i<=1000;i++) if (used[i]) for (int j=i*i;j<=1000000;j+=i) used[j]=false;
    for (i=2;i<=1000000;i++) if (used[i]) RideBack[last++]=i;
    while (scanf("%d",&i)!=EOF) printf("%d\n",bin_search(i));return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;


// cin >>
// cin <<
bool isPrime(int x){
	if(x==2) return true;
	if(x<2||x%2==0) return false;
	int i=3;
	while(i<=sqrt(x)){
		 if (x%i==0)return false;
		i= i+2;
	}
	return true;
}
int main(){
	int in[30]={};
	int out=0;
	for(int i=0;i<30;i++) cin >>in[i];
	for(int i=0;i<30;i++){
		if(in[i]==0){
			break;
		}else{
			out=0;
			for(int j=0;j<in[i]+1;j++){
				if(isPrime(j)==true){
					out++;
				}
			}
			cout <<out<<endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#define INF 999999
using namespace std;

int main()
{
	int n;
	
	while (cin >> n)
	{
		int ans = 0,rootn;

		int a[INF] ;
		
		rootn = sqrt(n)+1;
	
		for (int i = 2; i <= rootn; i++)
		{
			if (a[i]==0)
			{
				for (int j = i+1; j <= INF; j++)
				{
					if (a[j] == 0 && j%i == 0)
					{
						a[j] = 1;
					}
				}
			}
		}
		cout << "a" << endl;
		for (int i = 2; i <= n; i++)
		{
			if (a[i]==0)
				++ans;
		}
		cout << ans << endl;
	}
			
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	int N;
	bool is_prime[1000000];
	is_prime[0]=0; is_prime[1]=0;
	for(int i=2;i<1000000; i++){
		is_prime[i]=1;
	}
 
	for(int s=2; s<1000000; s++){
		if(is_prime[s]==1){	
		for(long long i=s*s; i<1000000; i+=s){
		is_prime[i]=0;	
 
		}
		}
	}
 
	while(cin >> N){
 
		int ans=0;
		for(int i=2; i<N+1; i++){
			ans+=is_prime[i];
		}
		cout << ans <<endl;
 
	}
return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int ans=0;
		for(int m=2;m<=n;m++){
			for(int i=2;i<=sqrt(m);i++){
				if(m%i==0){
					ans++;
					break;
				}
			}
		}
		cout<<n-ans-1<<endl;
	}
	return 0;
}