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++: #include<stdio.h>

int pr[50847534];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
        /*printf("O\n");*/
      return nxp;
    }else{
        /*printf("X\n");*/
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF){
        printf("n=%d\n",n);
        i=0;
        if(n-1){
            while(pr[i]<=n){
                printf("prime:%d(%d)\n",pr[i],i+1);
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
    }
}

C++: #include <iostream>

using namespace std;

bool is_prime(int x)
{
	if (x == 2) return true;
	if (x % 2 == 0) return false;
	for (int i = 3; i*i <= x; i += 2)
		if (x % i == 0)
			return false;

	return true;
}

int main()
{ 
	int n;

	while (cin >> n)
	{
		int cnt = 0;

		if (n > 1) cnt++;
		for (int i = 3; i <= n; i += 2)
			cnt += is_prime(i);

		cout << cnt << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool isprime(int& num)
{
    static int c;
    if(num == 2) return true;
    for(c=2; c <= sqrt(num); c+=1)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans = 0;
    int buff;
    while(cin >> buff);
    {
        for(int d =2; d <= buff; d++)
        {
            if(isprime(d)) ans++;
        }
        cout << ans << endl;
        ans  = 0;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;

while(~scanf("%d",&n)){
int* table =  new int[1000000];
memset(table,sizeof(table),1);
table[0]=0;

for(int i=1;i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j*=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+1000000,1));
}
}

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

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

int main(){
    int n;
    vector<int> S;
    double a=sqrt(n);
    while(cin>>n){
        S.push_back(2);
        int ans=0;
        for(int i=3; i<=a; i++){
            int judge=0;
            for(int j=0; j<S.size(); j++){
                if(i%S[j]==0)judge=1;
            }
            if(judge==0){
                ans++;
                S.push_back(i);

            }
        }
        cout<<ans+1<<endl;
        S.clear();
    }
    return 0;
}

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

int main()
{
	bool IsPrime[1000010] = {};
	for (int i = 2; i < 999999; i++)
	{ 
		IsPrime[i] = true;
	}
	for (int i = 2; i*i <= 999999; i++)
	{
		if (IsPrime[i])
		{
			for (int j = i * 2; j <= 999999; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}

	int n;
	while (cin >> n)
	{
		int ans = 0;
		for (int i = 0; i <= n; i++)
		{
			if (IsPrime[i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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

//C

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

int sieve(int n){
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = 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 = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
	}
	return p;
}

int main(){
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int ans = sieve(n);
		printf("%d\n", ans);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N;

constexpr ll max_n = 1000006;
bool prime[max_n];

void solve(){
    int cnt=0;
    for(int i=2;i<=N;i++) if(prime[i]) cnt++;
    cout << cnt << endl;
}

int main(){
    rep(i,max_n) prime[i]=true;
    for(int i=2;i<max_n;i++){
        if(!prime[i]) continue;
        for(int j=2;i*j<max_n;j++) prime[i*j] = false;
    }

    while(cin>>N){
        solve();
    }
}

C++: #include<stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i <= n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int sum[1000];
	int i, n;
	sum[0]=0;
	while(scanf("%d",&n) != EOF){
		for(i=2;i<=n;i++){
			if(isprime(i)){
				sum[i+1]=sum[i]+1;
			}else{
				sum[i+1]=sum[i];
			}
		}
		printf("%d\n",sum[n+1]);
	}
	return 0;
}