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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

ll eratosthenes(ll x){
    vbo isprime(x+1,true);
    isprime[0]=false;
    isprime[1]=false;
    ll p=0;
    for(ll i=2;i<=x;i++){
        if(isprime[i]){
            p++;
            for(ll j=2*i;j<=x;j+=i)isprime[j]=false;
        }
    }
    return p;
}

int main(){
    queue<int> q;
    int n;
    while(cin>>n)q.push(eratosthenes(n));
    while(q.size()){
        cout<<q.front()<<endl;
        q.pop();
    }
}

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

using namespace std;

int sosuu(int n);

int main(){
    int n=0;
    int num=0;
    int a[30]={0};
    int max=0;
    while(scanf("%d",&n)!=EOF){
        if(max<n){
            max=n;
        }
        a[num]=n;
        num++;
    }
    
    int b[max];
    for(int i=0; i<max; i++){
        b[i]=i;
    }
    b[1]=0;
    
    for(int i=2; i<sqrt(max); i++){
        for(int j=i+1; j<max; j++){
            if(j%i==0){
                b[j]=0;
            }
        }
    }
    for(int i=0; i<num; i++){
        int temp =a[i];
        a[i]=0;
        for(int j=0; j<=temp; j++){
            if(b[j]!=0){
                a[i]++;
            }
        }
        cout<<a[i]<<"\n";
    }
    
    
}
int sosuu(int n){
    if(n==2){
        return 1;
    }else{
        int temp=1;
        for(int i=0; i<n; i++){
            temp=temp*2;
        }
        if(temp%n!=2%n){
            return 0;
        }
        return 1;
    }
}

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] = {0};
		
		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++: nclude <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; continue;}
    for(int i=2; i<=n; i++) prime[i]=true;
    int ans=0;
    for(int i=2; i<=n; i++){
      if(prime[i]) {
        ans++;
        for(int j=2*i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}

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

int main()
{
     while(1){
     long int xx,sqrtx,q,count=1; 
     long double n;
	cin >> n;
	xx=n;
	sqrtx = sqrt(n);

	long int *ar = new long int [xx];
	long int *p = new long int [xx];
	for(long int i=2 ; i<=xx ; i++){    // 2〜xまでの整数
		ar[i]=i;
	}

	int i=2;
	do{
		if(ar[i]!=0){
			p[count]=i;
			count++;
		}
		for(int j=2*i ; j<=xx ; j+=i){
			ar[j]=0;
		}	
		i++;
	}while(i<sqrtx);

	cout << p[count-1] << endl;
        }
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=sqrt(j);i+=2){
				if(j%i==0)k++;
			}
			if(k==1)kk++;
		}
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<"1"<<endl;
		else cout<<kk+1<<endl;
	}
	return 0;
}

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

Int pn[1000002];

int main(){
int n, Count;
cin.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,n);
pn[0]=pn[1]=1;
for(int i=2;i<=n;i++) if(!pn[i]) for(int j=1;i*j<=n;j++) pn[i*j]=1;
Count=count(pn,pn+n,0);
cout<<Count<<endl;
}
return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

const int MAX_N = 1e6+5;
int prime[MAX_N];
bool is_prime[MAX_N];

int seive(int n) {
  rep(i, 0, MAX_N) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

  int p = 0;

  rep(i, 2, n+1) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
    }
  }

  return p;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  while (cin >> n) {
    cout << seive(n) << endl;
  }

  return 0;
};