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 <iostream>
#include <vector>

using namespace std;

int prime(int n) {
  int i, j, r;
  
  if (n < 2) return 0;
  vector<int> primes(n);

  for (i = 2; i < n; i++)
    primes[i] = i;
  for (i = 2; i*i < n; i++) {
    if (primes[i])
      for (j = i*i; j < n; j += i)
        primes[j] = 0;
  }
  for (i = 2, r = 0; i < n; i++)
    if (primes[i]) r++;
  return r;
}

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

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

int check(int x,int y,int z,int w){

}

int main(){
	int n;
	while(cin >> n){
		vector<int> prim;
		prim.push_back(2);
		for(int i=3;i<=n;i++){
			bool fl=false;
			for(int j=0;j<prim.size();j++){
				if(i%prim[j]==0){
					fl = true;
					break;
				}
			}
			if(fl==false) prim.push_back(i);
		}
		cout << prim.size() << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

vector<int> a;
void func(int n){

  for(int i = 0; i <= n; i++){
    a.push_back(1);
  }
  for(int i = 2; i * i <= n; i++){
    if(a[i]){
      for(int j = 2; i * j <= n; j++){
        a[i * j] = 0;
      }
    }
  }
  int cnt = 0;
  for(int i = 2; i <= n; i++){
    if(a[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}

int main(){
  int n;
  while(cin >> n){
    func(n);
  }
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> v;
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int a,i;
for(;;){
cin>>a;
for(int x=2x<a;x++){
if(a%x==0){i++}
cout<<i<<endl;
}
}
return 0;
}

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

int isprime[1000000];

void hurui() {
    isprime[0] = isprime[1] = 0;
    for (int i = 2; i < 1000000; i++) {
        isprime[i] = 1;
    }
    for (int i = 0; i < 1000000; i++) {
        if (isprime[i]) {
            for(int j = i * 2; j < 1000000; j+=i) {
                isprime[j] = 0;
            }
        }
    }
}

int main() {
    hurui();

    int N;
    while(cin >> N) {
        int count = 0;
        for (int i = 0; i <= N; i++) {
            if (isprime[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]){
        for(long long int j =i*i;j<MAX;j+=j){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

C++: #include<iostream>
using namespace std;
#define L long long int
int main(){
int n,ans,i,j;
while(cin>>n){
	ans=0;
	for(i=2;i<=n;i++){//search for 2 to n
		for(j=2;j<=i;j++)if(i%j==0)break;
		if(j==i)ans++;
	}
	cout<<ans<<endl;
}
system("pause");
return 0;
}

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

int main()
{
  int i, j;
  int n;
  int ans;
  int count;

  ans = 0;

  cin >> n;
  for (i = 2; i <= n; i++){
    count = 0;
    for (j = 1; j <= i; j++){
      if (i % j == 0){
        count++;
      }
    }

    if (count == 2){
      ans++;
    }
  }
  cout << ans << "\n";

  return (0);
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_INT = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int check(vector<bool> &v, int from, int to)
{
  int i;
  for (i = from + 1; i*i <= to && i*i < sz(v); i++) {
    if (v[i]) {
      for (int j = 2; i*j <= to && i*j < sz(v); j++) {
        v[i*j] = false;
      }
    }
  }
  return i - 1;
}

int count(vector<bool> &v, int to)
{
  int res = 0;
  repab (i, 2, to+1) {
    if (i >= sz(v))
      break;
    if (v[i])
      res++;
  }
  return res;
}

int main(int argc, char **argv)
{
  vector<bool> v(1000000);
  int done;

  rep (i , 1000000) {
    v[i] = true;
  }

  int n;
  done = 1;
  while (cin >> n) {
    done = check(v, done, n);
    cout << count(v, n) << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#define N 1000000

int main() {
	int ipt;
	int root;
	int cnt = 0;
	int A[N];
	for (int i = 1; i <= N; i++) {
		A[i] = i;
	}
	for (int pos = 2; pos <= N; pos++) {
		root = A[pos];
		if (!root)continue;
		for (int k = 2; k*root <= N; k++) {
			A[k*root] = 0;
		}
	}

	while(1) {
		scanf("%d", &ipt);
		for (int i = 2; i <= ipt; i++) {
			if (A[i] != 0)cnt++;
		}
		printf("%d\n", cnt);
		cnt = 0;
	}

	return 0;
}