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<vector>

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
//	vector<int> isPrime;
	bool isPrime[1000000];
	
	while(cin>>n)
	{
		for(int i = 0; i < n+1; i++){
//			isPrime.push_back(1);
			isPrime[i] = 1;
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n+1; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n+1; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin <= head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n+1; i++){
			if(isPrime[i] == 1){
				cont++;
		//		cout << "+"<<i << endl;
			}
		}
		printf("%d\n",cont);
	}
}

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

int main()
{
   int a,pp[100001];
   pp[0]=-1,pp[1]=-1;
   for(int i=2;i<100001;i++){
       if(pp[i]==0){
           pp[i]=1;
           for(int j=i*2;j<100001;j+=i){
               pp[j]=-1;
           }
       }
   }
   int now;
   while(cin>>now){
       int ans=0;
       for(int i=1;i<now+1;i++){
           if(pp[i]==1){
               ans++;
           }
       }
       cout<<ans<<endl;
   }
    return 0;
}

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

int main(int argc, char* argv[])
{
	int n;
	int judge(int s);
	while (scanf("%d",&n)!=EOF)
	{
	    int count=0; 
		for (int i=2;i<=n;i++)
		 {
		     if (judge(i)) count++;
		 }
		printf("%d\n",count);
	}
	return 0;
}
int judge(int s)
{
    for (int i=2;i<s;i++)
	{
	    if (s%i==0) return 0;
	}
	return true;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e8);
bool p[MAX];
int num[MAX];
void isPrime(){
  rep(i,MAX)p[i] = true;
  p[0] = p[1] = false;
  num[0] = num[1] = 0;
  loop(i,2,MAX){
    num[i] = num[i-1] + p[i];
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i){
	p[j] = false;
      }
    }
  }
}

int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<num[n]<<endl;
  
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)

#ifdef ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif

#define pb emplace_back
#define lb lower_bound
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

#define ALL(c) (c).begin(),(c).end()

#define DBG0(x)    {if(DEBUG){ cout << #x << ": " << x << "\t"; }}
#define DBG(x)     {if(DEBUG){DBG0(x); cout << endl;}}
#define DBG2(x, y) {if(DEBUG){DBG0(x); DBG(y);}}
#define DBG3(x, y, z) {if(DEBUG){DBG0(x); DBG2(y, z);}}
#define DBG4(w, x, y, z) {if(DEBUG){DBG0(w); DBG3(x, y, z);}}

template <class T>
ostream& operator<<(ostream& os, vector<T> xs){ for(T x: xs) os << x << ' '; return os; }
template <class S, class T>
ostream& operator<<(ostream& os, pair<S,T> st){ os << "(" << st.first << "," << st.second <<")"; return os; }

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

const int PN = 210000;
vint ps;
vector<bool> eratos;
void init_primes(void){
    eratos = vector<bool>(PN, false);
    ps.clear();
    for(int i = 2; i < PN; ++i){
        if(!eratos[i]){
            ps.pb(i);
            for(int j = i; j < PN; j += i)
                eratos[j] = true;
        }
    }
    return;
}
int main(void){
    init_primes();
    int n;
    while(cin >> n){
        if(n < 2){
            cout << 0 << endl;
            continue;
        }
        int l = 0, r = ps.size() - 1;
        while(r - l > 1){
            int med = (l + r) / 2;
            if(ps[med] <= n) l = med;
            else r = med;
        }
        cout << l + 1 << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<math.h>
int main(void)
{
	long n,a,range;
	double b;
	bool flag;
	while(scanf("%d",&range)!=EOF){
	long t=0;
	for(int i=2;i<=range;i++){
		n=i;
	a=2;
	b=sqrt(n);
	flag=false;
	while(a<=b)
	{
		if(n%a==0){
			flag=true;
			break;
		}else{
			a++;
		}
	}
	if(flag==false){
			t++;
	}
	}
	printf("%d\n",t);

}

	return 0;
}

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

using namespace std;

int main() {
	int n;

	while (cin >> n) {
		int counter = 0;
		
		if(n < 1000){
			for (int i = 2; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		}else if(n < 10000){
			counter = counter + 168;
			for (int i = 1000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 100000){
			counter = counter + 1229;
			for (int i = 10000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 200000){
			counter = counter + 9592;
			for (int i = 100000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 300000){
			counter = counter + 17984;
			for (int i = 200000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else {
			counter = counter + 25997;
			for (int i = 300000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		}
		cout << counter << endl;
	}

	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> vi;
vi primes;

int get_primes(int max){
	int n = (max+1)/2;
	int root = (int)(pow(n, 0.5));
	vector <bool> numbers(n, true);
	numbers[0]=false;

	if (max>1) primes.push_back(2);
	for (int i=1; i<root; i++){
		int tmp = i*2+1;
		if (numbers[i]){
			primes.push_back(tmp);
			for (int j=i+tmp; j<n+1; j+=tmp){
				numbers[j]=false;
			}
		}
	}
	for (int i=root; i<n+1; i++){
		if(numbers[i]){
			primes.push_back(2*i+1);
		}
	}
	return 0;
}

int main(void){
	vi n;
	int nmax=0;
	while (true){
		int tmp;
		cin>>tmp;
		if (cin.eof()) break;

		n.push_back(tmp);
		if (tmp>nmax) nmax=tmp;
	}

	get_primes(nmax);
	for (int i=0; i<n.size(); i++){
		cout<<upper_bound(primes.begin(), primes.end(), n[i]) - primes.begin()<<endl;
	}
	return 0;
}