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

typedef long long LL;
using namespace std;

const int X = 1000001;
bool Find[X];

void init(){
  for(int i=0;i<X;i++){
    Find[i] = false;
  }
  for(int i=2;i<=sqrt(X);i++){
    if(Find[i])continue;
    for(int j=i+1;j<X;j++){
      if(Find[j])continue;
      if(j%i==0)Find[j]=true;
    }
  }
}

int main(){
  init();
  int n;
  while(cin >> n){
    int answer = 0;
    for(int i=2;i<n+1;i++){
      if(!Find[i])answer++;
    }
    cout << answer << endl;
  }
  return 0;
}

C++: #include <stdio.h>

int main(){
	int n;
	while(scanf("%d", &n) != EOF){
		int *arr = new int[n + 1];
		
		for(int i = 2; i <= n; i++){
			if(arr[i] == 0){
				for(int j = 2*i; j <= n; j += i){
					arr[j] = 1;
				}
			}
		}
		
		int cnt = 0;
		for(int i = 2; i <= n; i++){
			if(arr[i] == 0){
				cnt++;
			}
		}
		delete [] arr;
		
		printf("%d\n", cnt);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int cnt=0,res=0;
    for(int i=2; i<=n; i++){
      for(int j=1; j<=n; j++){
        if(i%j == 0) cnt++;
      }
      if(cnt==2) res++;
      cnt = 0;
    }
    cout << res << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <cmath>
int n;
int num;
int main()
{
    scanf("%d",&n);
    if(n==0||n==1)
    {
        printf("%d\n",num);
        return 0;
    }
    for(int i=2;i<=n;i++)
    {
    // i 是不是 prime
        bool isp=true;
        int m=sqrt(i);
        for(int j=2;j<=m;j++)
        {
            if(i%j==0)
            {
                isp=false;
                break;
            }
        }
        if(isp)
            num++;//n[i]的素数+1
    }
    printf("%d\n",num);
    return 0;
}

C++: #include <iostream>
#include <math>

using namespace std;

int main() {
  int lim;
  int i,n;
  int count=1;
  bool isPrime=true;
  
  scanf("%d",&n);
  
  for(lim=2;lim<=n;lim++) {
  for(i=2;i<(int)(sqrt(lim)+1.0);i++) {
    if((lim%i)==0) {
      isPrime=false;
      count++;
      break;
    }
  }
  }
  printf("%d",n-count);
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string.h>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	bool fl[1000001];
	memset(fl, true, sizeof(fl));
	for (int i = 2; i <= sqrt(num); i++) {
		if (fl[i]) {
			for (int j = 2; j*i <= num; j++) {
				fl[i*j] = false;
			}
		}
	}
	for (int i = 2; i <= num; i++) {
		if (fl[i]) {
			count++;
		}
	}
	return count;
}

int main() {

	int num = 0;
	while (cin >> num) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

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

#define MAXN 1000000

int primeN[MAXN];

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

void calcPrimeN()
{
	primeN[0] = 0;
	for(int i=1; i<MAXN; i++)
	{
		if(isPrime(i)) primeN[i] = primeN[i-1] + 1;
		else primeN[i] = primeN[i-1];
	}
}

int main()
{
	calcPrimeN();
	
	int data;
	while(cin >> data)
	{
		cout << primeN[data] << endl;
	}

	return 0;
}

C++: #pragma GCC optimize "O3"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double EPS = 1e-10;
const double PI  = acos(-1.0);

vector<bool> ptable;

void sieve(LL max) {
	if(max+1 > ptable.size())
		ptable.resize(max+1, true);

	ptable[0] = ptable[1] = false;

	for(LL i = 2; i*i <= max; i++)
		if(ptable[i])
			for(LL j = 2; i*j <= max; j++)
				ptable[i*j] = false;
}

int main(int argc, char *argv[]) {
	// Something to do
	sieve(1000000);
	int n;
	while(cin >> n) {
		int cnt = count(ptable.begin(), ptable.begin()+n+1, true);
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>

int main() {
	int input;
	// ??\???????????°????????????????????????????????????
	while (std::cin >> input) {
	int count = 0;
	for (; input > 1; input--) {
		bool fl = true;
		for (int i = 2; fl == true, i < input; i++)
			if (!(input % i))
				fl = false;

		if (fl)
			count++;
	}

			std::cout << count << std::endl;
	}
}