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 := 2; j < i-1; j++ {
				if i%j == 0 && j != 1 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;


vector<int> p;
int main(void){
    p.pb(2);
    for(int i = 3; i <1000000; i += 2){
        int j;
        for(j = 0; p[j] * p[j] <= i; ++j){
            if(i % p[j] == 0) break;
        }
        if(i % p[j] > 0) p.pb(i);
    }
    int n;
    while(cin >> n){
        if(n == 1){
            cout << 0 << endl;
            continue;
        }
        int l = 0, r = p.size();
        while(l + 1 != r){
            int t = (l + r)/2;
            if(p[t] <= n) l = t;
            else r = t;
        }
        int ret = r + 1;
        while(n < p[ret]) ret--;
        cout << ret + 1<< endl;
    }
    return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <map>
 
inline 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;
    }
}
 
inline 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;
    m[3] = 2;
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 5; i <= n; i += 2) {
            if (m.count(i) > 0)
                continue;
 
            m[i] = m[i - 2] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", m[n % 2 == 0 ? n - 1 : n]);
    }
}

C++: int primes[78498], num_primes;
int calculated;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	calculated = 2;
	num_primes = 1;
	while (true) {
		int n;
		if (!scanf("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				int max = (int)(sqrt(i)) + 1;
				for (int j=1; primes[j] < max&&j<num_primes; j++) {
					if (i%primes[j] == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{

long long  n,f=1,c=0;
cin>>n;
for(long long i=2;i<=n;i++)
{
    if(i==2){f=1;c++;continue;}
    for(long long j=2;j<i;j++)
    {
        if(i%j==0){f=0;break;}
        else f=1;
    }
    if(f==1)c++;
}
cout<<c;
    return 0;
}

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

int a[1000000];

int main()
{
  int n;
  int count;

  for (int i = 2; i < 1000000; i++){
     a[i] = 1;
   }

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

   while (cin >> n){
     count = 0;
     for (int i = 0; i < 1000000; i++){
       if (a[i] == 1){
         count++;
       }
     }
   }

   cout << n << endl;

   return (1);
}

C++: 
#include<iostream>
#pragma warning(disable:4996)
#define MAX_N 1000000
using namespace std;

int prime[MAX_N];//第i个素数
bool is_prime[MAX_N + 1];//is_pime[i]?true表示i?素数

//返回n以内素数的个数
int sieve(int n){
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++){
		if (is_prime[i]){
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
	}
	return p;

}

int main(){
	int n;
	while (scanf("%d", &n) != EOF){
		printf("%d\n", sieve(n));
	}

}

C++: #include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
int prime[maxn];
bool is_prime[maxn];
int sieve(int n) {
	int p = 0;

	for(int i=2; i<=n; i++) {
		if(is_prime[i]) {
			prime[p++] = i;
			for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
		}
	}
	return p;
}
int main() {
	int n;
	for(int i=0; i<=maxn; i++) is_prime[i] = true;
	//0???1???????´???°
	is_prime[0] = is_prime[1] = false;
	while(~scanf("%d",&n)) {

		int p = sieve(n);
		printf("%d\n",p);
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define NUM 1000000
int main(){
	long int n;
	int p[NUM],i,j,k,a,b;
	for(i=0;i<NUM;i++){
		p[i]=0;
	}
	for(i=2;i<NUM;i++){
		if(p[i]==0){
			p[i]=2;
			for(j=2;j<(NUM/i);j++){
				p[i*j]=1;
			}
		}	
	}
	while(cin>>n){
		a=0;
		for(i=2;i<=n;i++){
			if(p[i]==2)a++;
		}
		cout<<a<<endl;
	}
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
const int SIZE = 1000000;
bool mark[SIZE];
long long int num[SIZE];
void findp(){
    memset(mark, true, sizeof(mark));
    for(int i = 2; i <= sqrt(SIZE); i ++){
        if(mark[i]){
            for(int j = i + i; j < SIZE; j += i){
                mark[j] = false;
            }
        }
    }
    num[1] = 0;
    for(int i = 2; i < SIZE; i ++){
        num[i] = num[i-1];
        if(mark[i]){
            num[i] += 1;
        }
    }
}
int main(){
    int n;
    findp();
    while(cin>>n){
        printf("%ld\n", num[n]);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
bool isprime[1000005];
int prime[1000005];
void sieve() {
	for (int i = 0; i <= 1000000; i++) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= 1000000; i++) {
		if (isprime[i]) {
			prime[i] = prime[i - 1] + 1;
			for (int j = 2 * i; j <= 1000000; j += i) isprime[j] = false;
		}
		else prime[i] = prime[i - 1];
	}
}
int main() {
	sieve();
	int n;
	while (cin >> n) {
		cout << prime[n] << endl;
	}
}