Go: package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		flag := false
		count := 0

		for i := 2; i <= num; i++ { //1を除く入力値以下の数字
			for j := i - 1; j >= 1; j-- {
				if i%j == 0 && j != 1 {
					flag = true
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int isprime(int x){
    if(x==2||x==3) return true;
    if(x<5||x%2==0||x%3==0) return false;
    else{
        int i=5;
        while(i<=sqrt(x)){
            if(x%i==0) return false;
            i = i+2;
        }
        return true;
    }
}
int main() {
    int n;
    while(cin >> n){
        int ans=0;
    for (int j=n; j>1; j--) {
        if(isprime(j)!=0) ans++;
    }
    cout << ans << endl;
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool era[10000000]={false};
 
 
void makeERA(){
    for(int i=2;i<1000001;i++){
        if(era[i]!=true)continue;
        for(int j=2;;j++){
            if(i*j<=1000000)
                era[i*j]=false;
            else break;
        }
    }
    era[2]=true;
}
int main(){
    rep(i,10000000)era[i]=true;
    era[0]=false;era[1]=false;
	makeERA();
	int n;
	while(cin>>n){
		if(n==0)break;

		int sum=0;

		rep(i,n+1){
			if(era[i])sum++;
		}
		cout<<sum<<endl;
	}
}

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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {
    int n; // 10000
    scanf("%d", &n);

    int cnt = 0;
    REP(2, i, n) {
        if (isPrime(i)) cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		v.push_back(n);
	}
	for(int i = 0; i < v.size(); i++){
		for(int j = 2; j <= v[i]; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: #include <cmath>
#include <cstdio>
#include <map>

bool fermat_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
    }
}

bool prime_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
            if ((n %= i) == 0) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    std::map<int, int> m;
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 2; i <= n; ++i) {
            if (m.count(i) > 0)
                continue;

            m[i] = m[i - 1] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", m[n]);
    }
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 1000000
using namespace std;

int num[MAXNUM]={0};

int main(){
  int n;
  FOR(i, 2, (MAXNUM)/2){
    num[2*i]=1;
  }
  while(cin >> n){
    int ans=0;
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      if(num[i]!=0) continue;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        for(int j=2; j<=n; j++){
          if(j*i > n) break;
          num[j*i]=1;
        }
      }
    }
    FOR(i, 2, n+1){
      if(num[i]==0){
        ans++;
      }
    }
    cout << ans << endl;;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
    int n, ans, cnt, prime;

    while(cin >> n){
      prime = 1;
      if(n == 1) cout << 0 << endl;
      if(n == 2) cout << 1 << endl;
      if(n == 3) cout << 2 << endl;

      if(n >= 4){
      for(int i=3; i <= n; i++){
        cnt = 0;
        for(int j=3; j <= sqrt(i); j += 2){
          if(i%j == 0) cnt++;
        }
        if(cnt == 0  && i%2 != 0) prime++;
      }
      cout << prime << endl;
    }
    }
    return 0;
}

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

#define MAX 1000000 

bool prime_table[MAX];
int head;

int main(){
	int n, i, j;
	int result;
	// make table
	for (i = 0; i < MAX; i++) {
		if(i==0||i==1){
			prime_table[i] = false;
		}else{
			prime_table[i] = true;
		}
	}
	// find prime
	for (i = 2; i < MAX; i++) {
		if(prime_table[i]){
			for (j = i+i; j < MAX; j+=i) {
				prime_table[j] = false;
			}
		}
	}
	
	while(cin >> n){
		result = 0;
		for (i = 0; i <= n; i++) {
			if(prime_table[i])
				result++;
		}
		cout << result << endl;
	}
	return 0;
}

C++: //36
#include<iostream>
 
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 1000000;

int sum[MAXN+5];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    sum[1] = 0;
    for (int i = 2; i <= MAXN; i++) {
        if (sum[i] == 0) {
            for (int j = i + i; j <= MAXN; j += i) {
                sum[j] = 1;
            }
        }
        sum[i] = sum[i - 1] + !sum[i];
    }

    int N;
    while (cin >> N) {
        cout << sum[N] << "\n";
    }
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main(void){
	int i,j,k,n,a=1;
	cin >> n;
	if(n==1){
		cout << "0\n";
		return 0;
	}
	for(i=3;i<=n;i+=2){
		k=0;
		for(j=3;j<=sqrt(i);j+=2){
			if(i%j==0){
				k=1;
				break;
			}
		}

		if(k==0) a++;
	}

	printf("%d\n",a);
	return 0;
}