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 <vector>
#include <cmath>
using namespace std;

int count_prime_number(int n){
	if(n < 2){
		return 0;
	}
	if(n == 2){
		return 1;
	}
	int count = 1;	//2??????
	for(int i = 3; i <= n; i += 2){
		int k = 0;
		for(int j = 3; j <= sqrt(i); j += 2){
			if(i % j == 0){
				k=1;
				break;
			}
		}
		if(k==0){
			count++;
		}
	}
	return count;
}

int main(){
	vector<int> results;
	int in_num;
	while(cin >> in_num){
		results.push_back(count_prime_number(in_num));
	}
	for(auto result : results){
		cout << result << endl;
	}
	return 0;
}

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

bool prime[1000000];//false -> prime
int main(){
    int n = 1000000;

    prime[0] = prime[1] = true;
    for(int i = 2;i*i <= n;i++){

        if(prime[i] == false){
            for(int j = i*i;j <= n;j+=i){
                prime[j] = true;
            }
        }
    }
    while(cin>>n){
        int cnt = 0;
        for(int i = 0;i <= n;i++){
            if(prime[i] == false)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

C++: 
//  test.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    long int j,s[1000000]={0},d=1,i,n,k;
    
    s[0]=s[1]=1;
    
    for(i=2;i<1000000;i++){
        if(s[i]==0){
            
            for(j=2;j*j<=i;j+=2){
                if(i%j==0)
                    break;
                if(j==2)
                    j=1;
            }
            
            
            if(j*j>i){
                d++;
                if(i<1000){
                    for(k=2;k*i<1000000;k++){
                        s[k*i]=-1;
                    }
                }
            }
        }
        s[i] = d;
    }
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]-1);
    }
    
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  int n;
  while (cin >> n) {
    int ret = 0;
    for (int i = 2; i <= n; ++i) {
      bool flag = true;
      for (int j = 2; j * j <= i; ++j) {
        if (i % j == 0)
          flag = false;
      }
      if (flag) {
        ret++;
      }
    }
    cout << ret << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

bool isPrime[1000006];
ll cnt[1000007] = {0};
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	fill(isPrime, isPrime+1000006, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i <= 1000005; ++i) {
		for (int j = i*2; j <= 1000005; j += i) {
			isPrime[j] = false;
		}
	}
	REP(i, 1000006) {
		cnt[i+1] = cnt[i] + (isPrime[i] ? 1 : 0);
	}
	int N;
	while ( cin >> N ) {
		cout << cnt[N+1] << endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;


int main()
{
	int i,j,n,flag,number=0;
	
	while(cin>>n){
		number=0;
	for(j=2;j<=n;j++){
		flag=0;
		for(i=2;i<j-1;i++)
		{
		if(j%i==0)flag=1;
		}
		if(flag!=1)number++;
		
	}
	cout<< number << endl;
	}
	//cout<< number << endl;
	return (0);
}

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

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt;

    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        for (int i=2; i<n; i++){
            if (IsPrime(i)) cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

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

int a[999999];
int b[999999];

int prime(int x) {
	if (a[x] == 1) return 1;
	else if (a[x] == 2) return 0;
	for (int i = 2; i < sqrt(x) + 1; i++) {
		if (x%i == 0) {
			a[x] = 2;
			return 0;
		}
	}
	return a[x]=1;
}
int main(){
	int n;
	b[0] = 0;
	b[1] = 0;
	b[2] = 1;
	a[0] = 2;
	a[1] = 2;
	a[2] = 1;
	int count = 1;
	for (int i = 3; i <= 999999; i++) {
		if (prime(i))count++;
		b[i] = count;
	}
	while (scanf("%d", &n) != EOF){
		printf("%d\n", b[n]);
	}
	return 0;
}

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

int isPrime(int n){
	for(int i=2; i*i<=n; ++i){
		if(n % i == 0){
			return 0;
		}
	}
	return 1;
}

#define MAX_N 1000000

int ans[MAX_N];

main(){
	ans[0] = 0;
	ans[1] = 0;
	for(int i=2; i<MAX_N; i++){
		ans[i] = ans[i-1] + isPrime(i);
	}
	
	int n;
	while(cin>>n){
		cout << ans[n] << endl;
	}
}

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

int main()
{
	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}
	
	int n_prime[1000000];
	
	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		
		n_prime[i]=cnt;
	}
	
	while(true){
		int n;
		cin>>n;
		if(cin.eof())
			break;
		
		cout<<n_prime[n]<<endl;
	}
	
	return 0;
}