Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

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

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

int prime(int n){
  long long cnt=0;
  bool f[n+1];
  for(int i=0;i<=n;i++){
    f[i]=true;
  }
  f[0]=f[1]=false;
  for(int i=2;i<=n;i++){
    if(f[i]){
      cnt++;
      for(int j=2*i;j<=n;j+=i){
        f[j]=false;
      }
    }
  }
  return cnt;
}

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

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool isprime[1000000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 1000000; i++) {
		isprime[i] = true;
	}
	while (cin >> n && checkcnt < 30) {
		cnt = 0;
		int i;
		for (i = 2; i < sqrt(n); i++) {
			if (isprime[i]) {
				for (int j = 2; j <= n / i; j++) {
					isprime[i * j] = false;
				}
			}
		}
		for (int k = 2; k <= n; k++) {
			if (isprime[k]) {
				cnt++;
			}
		}
		cout << cnt << endl;
		checkcnt++;
	}
	return 0;
}

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

bool isPrime(int x) {
  if(x == 2) {
	return true;
  }
  
  if(x < 2 || x % 2 == 0) {
	return false;
  }
  for(int i = 3; i <= (int)sqrt(x); i += 2) {
	if(x % i == 0) {
	  return false;
	}
  }
  return true;
}

int main() {
  int n;
  bool a[1000000];

  for(int i = 1; i < 1000000; ++i) {
	if(isPrime(i)) {
	  a[i] = true;
	}
  }
  /*
  for(int i = 1; i < 10000; ++i) {
	if(isPrime(i)) {
	  cout << i << " ";
	}
  }
  */
  while(cin >> n) {
	cout << accumulate(&a[1], &a[n + 1], 0) << endl;
  }
  return 0;
}

/*-- primitive algorithm --*/
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
	if(n % i == 0) return false;
  }
  return true;
}
*/

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


/*
//my header
#include "define.h"
#include "geometry.h"*/

#define MyAbs(a) ((a)>0?(a):-(a))
#define MyEqualDoule(a,b) (MyAbs(a-b)<1e-6)

#define foreach(i,n) for(i=0;i<n;++i)
#define foreachd(i,n) for(int i=0;i<n;++i)
#define printfInt1(n) printf("%d\n",n)
#define scanfInt1(n) scanf("%d",&n)
#define scanfInt2(a,b) scanf("%d%d", &a, &b)
#define scanfInt3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scanfFloat2(a,b) scanf("%f%f", &a,&b)


void init()
{
#ifdef _WIN32
	freopen("1.txt", "r", stdin);
#endif
}

void func();

int main()
{
	init();
	func();

	return 0;
}

class CNumberTheory
{
public:
	//譛?、ァ蜈ャ郤ヲ謨ー
	static int gcd(int a, int b)
	{
		int t;
		while (b) {
			t = a % b;
			a = b;
			b = t;
		}
		return a;
	}
	//譛?ー丞?蛟肴焚
	static int lcm(int a,int b)
	{
		return a / gcd(a,b) * b;
	}
	//郤ソ諤ァ逕滓?蟆丈コ守ュ我コ始逧?エ?焚,螯よ棡a譏ッ邏?焚?碁ぅ荵?ns[a] = true
	static void GenePrimeJudge(int n, bool* ans)
	{
		memset(ans, true, sizeof(bool) * (n+1));
		ans[0] = false;
		ans[1] = false;
		int i;
		for(i = 2; i <= n; ++ i)
		{
			if(ans[i])
			{
				int j = 2;
				int k;
				while((k = i * j++) <= n)
					ans[k] = false;
			}
		}
	}
	//郤ソ諤ァ逕滓?蟆丈コ守ュ我コ始逧?エ?焚,螯Ｑrime[size = p]荳ュ蟄俶叛蟆丈コ始逧?エ?焚
	static void GenePrimeList(int n, int *prime, int& p)
	{
		bool* ans = new bool[n+1];
		memset(ans, true, sizeof(bool) * (n+1));
		ans[0] = false;
		ans[1] = false;
		p = 0;
		int i;
		for(i = 2; i <= n; ++ i)
		{
			if(ans[i])
			{
				prime[p++] = i;
				int j = 2;
				int k;
				while((k = i * j++) <= n)
					ans[k] = false;
			}
		}
	}

	//郤ソ諤ァ逕滓?蟆丈コ守ュ我コ始逧?エ?焚,螯よ棡a譏ッ邏?焚?碁ぅ荵?ns[a] = true,蟷カ荳廃rime[size = p]荳ュ蟄俶叛蟆丈コ始逧?エ?焚
	static void GenePrimeJudgeAndList(int n, bool* ans, int *prime, int& p)
	{
		memset(ans, true, sizeof(bool) * (n+1));
		ans[0] = false;
		ans[1] = false;
		p = 0;
		int i;
		for(i = 2; i <= n; ++ i)
		{
			if(ans[i])
			{
				prime[p++] = i;
				int j = 2;
				int k;
				while((k = i * j++) <= n)
					ans[k] = false;
			}
		}
	}
};

class CSearch
{
public:
	//扈吝ョ壻ク?クェ譛牙コ擾シ磯撼髯榊コ擾シ画焚扈Б?梧アゆササ諢丈ク?クェi菴ソ蠕輸[i]遲我コ嗣ey?御ク榊ュ伜惠蛻呵ソ泌屓-1
	static int BinarySearch(int key, int* arr, int n)
	{
		int l = 0, r = n - 1;
		while(l <= r)
		{
			int mid = (r + l)>>1;
			if(arr[mid] == key)
				return mid;
			if(arr[mid] < key)
				l = mid + 1;
			else
				r = mid + 1;
		}
		return -1;
	}

	//扈吝ョ壻ク?クェ譛牙コ擾シ磯撼髯榊コ擾シ画焚扈Б?悟庄蜷ォ譛蛾?螟榊?邏?シ梧アよ怙蟆冗噪i菴ソ蠕輸[i]螟ァ莠嗣ey?御ク榊ュ伜惠蛻呵ソ泌屓-1
	static int BinarySearch_FirstPos_Greater(int key, int* arr, int n)
	{
		int l = 0, r = n - 1;
		while(l < r)
		{
			int mid = (r + l)>>1;
			if(arr[mid] > key)
				r = mid;
			else
				l = mid + 1;
		}
		return arr[r] > key ? r: -1;
	}
};

bool ans[1000000];
int prime[100000];

void func()
{
	int p;
	CNumberTheory::GenePrimeJudgeAndList(999999, ans, prime, p);

	int n;
	while(~scanf("%d", &n))
	{
		int ret;;
		ret = CSearch::BinarySearch_FirstPos_Greater(n,prime,p);
		if(ret == -1)
			ret = p;
		printfInt1(ret);
	}
}

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

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j] = true;
		}
		}
		t[i]=t[i-1]+!c[i];
	}
	for(int n;cin>>n;n++){
		cout << n << endl;
	}
	return 0;
}

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

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;
}

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;

		bool a[INF] ;
		a[0] = false; a[1] = false;

		rootn = sqrt(n)+1;
	
		for (int i = 2; i <= rootn; i++)
		{
			if (a[i]==true)
			{
				for (int j = i+1; j < INF; j++)
				{
					if (a[j] == true && j%i == 0)a[j] = false;
				}
			}
		}
		for (int i = 0; i <= n; i++)
		{
			if (a[i]==true)++ans;
		}
		cout << ans << endl;
	}
			
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {

	int n;
	int *k;
	
	while (cin >> n) {
		int counter = 0;
		k = (int *)malloc(sizeof(int) * n);
		if (k == NULL) {
			exit(0);
		}
		k[0] = 1;
		for (int i = 1; i < n; i++) {
			k[i] = 0;
		}

		for (int i = 1; i < n; i++) {
			if (k[i] == 0) {
				/*for (int j = 1; j < i; j++) {
					if (k[j] == 0) {
						if ((i+1) % (j+1) == 0) {
							k[i] = 1;
							break;
						}
					}
				}*/
				if (k[i] == 0) {
					for (int t = 2; t <= n/(i+1); t++) {
						k[(i+1)*t-1] = 1;
					}
				}
			}
		}

		for (int i = 1; i < n; i++) {
			if (k[i] == 0) {
				counter++;
			}
		}

		cout << counter << endl;

		free(k);
	}

	return 0;
}