Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
//#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 1e6;

bool vis[maxn];
vector<int> Prms(maxn);

void seive(int n) //sqrt(n)
{
    int m = sqrt(n+0.5);
    for(int i = 2; i <= m; i++){
        if(!vis[i])
        for(int j = i*i; j <= n; j += i){
            vis[j] = true;
        }
    }
    Prms.clear();
    for(int i = 2; i <= n; i++)
        if(!vis[i])
        Prms.push_back(i);
}

//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    seive(maxn);
    int n;
    while(~scanf("%d",&n)){
        int ans = upper_bound(Prms.begin(),Prms.end(),n)-Prms.begin();
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
using ppa = pair<pa,int>;
#define SORT(v, n) sort(v, v+n);
#define ALL(v) v.begin(),v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v),greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

//4??????
//int dy[]={0, 1, 0, -1};
//int dx[]={1, 0, -1, 0};

//8??????
//int dy[]={0,0,1,-1,1,1,-1,-1};
//int dx[]={1,-1,0,0,1,-1,1,-1};

const ll MOD = 1000000007;

ll pow_mod(ll a,ll b,ll mod){
    ll tmp = 1;
    a %= mod;
    if(b > 0){
        tmp = pow_mod(a, b/2, mod);
        if(b % 2) tmp = (((tmp*tmp)%mod)*a)%mod;
        else tmp = (tmp*tmp)%mod;
    }
    return tmp;
}

int mm = 1000000;
vector<bool> d(mm);

void hoge(){
    d[0] = d[1] = true;
    FOR(i,2,mm){
        if(d[i]) continue;
        for(int j = 2; i*j <= mm; j++){
            d[i*j] = true;
        }
    }
}

void solve() {
    vector<int> dp(mm,INF);
    int val;
    int m = 2;
    dp[0] = dp[1] = 0;
    hoge();
    while(cin >> val){
        if(dp[val] == INF){
            FOR(i,m,val+1){
                dp[i] = dp[i-1] + (!d[i] ? 1 : 0);
            }
            m = val;
        }
        cout << dp[val] << endl;
    }
}

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

    solve();

    return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
    int n;
    while (cin >> n)
    {
        int p[n + 1];
        for (int i = 0; i < n + 1; i++)
        {
            p[i] = 1;
        }
        p[0] = 0;
        p[1] = 0;
        for (int i = 2; i <= sqrt(n); i++)
        {
            for (int j = 2; i * j <= n; j++)
            {
                p[i * j] = 0;
            }
        }
        int c = 0;
        for (int i = 0; i <= n; i++)
        {
            if (p[i] == 1)
            {
                c++;
            }
        }
        cout << c << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int ar[1000009];
int pr[1000009];
int main()
{
    int i,n,j,k,z=2,te;
    for(i=4;i<=100009;i+=2){
        ar[i]=1;
    }

    pr[3]=1;
    int sq=sqrt(1000000)+3;
    for(i=3;i<=1000009;i+=2){

            if(ar[i]==0){pr[i+1]=z++;}
            if(i<=1000){
                if(ar[i]==0){
                    for(j=i*i;j<=1000009;j+=2*i){
                        ar[j]=1;
                    }
                }
            }
    }
    for(i=0;i<1000009;i++){
        if(pr[i]!=0){
            te=pr[i];
        }
        pr[i]=te;
    }




    while(scanf("%d",&n)==1){
            if(n>1){printf("%d\n",pr[n+1]);}
            else {
                printf("0\n");
            }
    }
    return 0;

}

C++: #include <cstdio>
#include <bitset>
using namespace std;
int c[999999]={0,1};
int main() {
	bitset<499999> b;
	int i,j,n=3;
	for(i=0;n*n<=999999;i++,n+=2) {
		if(b[i])continue;
		for(j=i+n;j<499999;j+=n)b[j]=1;
	}
	for(i=0,n=3;i<=499998;i++,n+=2) {
		if(!b[i])c[n-1]=c[n]=c[n-2]+1;
		else c[n-1]=c[n]=c[n-2];
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n-1]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define MAX 1000000
#define LMT 1000
unsigned flag[MAX>>6];
int primes[6000000];//5761455
#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))

int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    return 0;
}

int main()
{
    sieve();
    unsigned int i,L;
    int k=1, count;
    primes[0]=2;
    while(scanf("%d", &L)==1)
    {
        count=1;
        for( i=3; i<=L; i+=2)
        {
            if(ifc(i)==0)
                count++;
        }
        if(L>1)
            printf("%d\n", count);
        else printf("0\n");
    }
    return 0;
}

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

int main(void)
{
    int count=0;
    int i=1;
    int n=1;
    int number;
    // insert code here...
    while (cin >> number, number != EOF){
        while (n <= number){
            if(n == 1) {n++; continue;}
            while (i <= n) {
                if(i == 1) {i++; continue;}
                if(i == n) count++;
                if(n % i == 0) break;
                i++;
            }
            n++;
            i=1;
        }
        i=1;
        n=1;
        cout << count << endl;
        count = 0;
    }
    return 0;
}

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

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

int main(){
	int n;
	while(cin>>n){
		int sum=0;
		for(int i=2;i<=n;i++){
			if(isprime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main() {
	bool prime[N];
	prime[0] = prime[1] = false;

	//initialize
	for(int i=2; i<N; i++) prime[i] = true;
	cout<<"End Initialize prime array!"<<endl;
	//Sieve of Eratosthenes
	for(int i=2; i<=N/2; i++){
		if(prime[i]){
			for(int j=2; i*j<=N; j++)
			{
				prime[i*j] = false;
			}
		}
	}
	cout<<"End Sieve of Eratosthenes"<<endl;

	int countPrime[N];
	int cnt = 0;
	for(int i=0; i<N; i++){
		if(prime[i]){
			cnt++;
		}
		countPrime[i] = cnt;
	}

	int input;
	while(true) {
		cin>>input;
		if(cin.eof()){break;}
		cout<<countPrime[input]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 int n, i, j, k;
 int b;
 int count = 0;
 
 

 while(cin >> n){
  int a[n+1];
  for(i = 2;i < n+1;i++){
    a[i] = i;
  }


  for(i = 2;i*i < n;i++){
    if(a[i] != 0){
      b = a[i];
     }
    for(j = 2;j*b < n+1;j++){
      a[j*b] = 0;
    }
  }
  for(i = 2;i < n+1;i++){
    if(a[i] != 0){
      count++; 
    }
  }
  cout << count << endl;
  count = 0;
  
  
 }

 return 0; 
}