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

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

using namespace std;

class Prime {
private:
  vector<long long> divisor;
  
public:
  Prime(long long n) {
    for (long long i = 0; i < n; ++i) divisor.emplace_back(i);
    for (long long i = 2; i <= n / i; ++i) if (divisor[i] == i) {
      for (long long j = i * i; j < n; j += i) divisor[j] = i;
    }
  }
  
  bool isPrime(long long n) {
    if (n <= 1) return false;
    if (n < (long long)divisor.size()) return divisor[n] == n;
    for (long long i = 2; i <= n / i; ++i) if (n % i == 0) return false;
    return true;
  }
  
  vector<long long> factor(long long n) {
    vector<long long> res;
    for (long long i = 2; i <= n / i && n >= (long long) divisor.size(); ++i) {
      while (n % i == 0) {
        res.emplace_back(i);
        n /= i;
      }
    }
    if (n >= (long long)divisor.size()) {
      res.emplace_back(n);
    } else {
      while (n > 1) {
        res.emplace_back(divisor[n]);
        n /= divisor[n];
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
  
  vector<long long> divisors(long long n) {
    vector<long long> res;
    for (long long i = 2; i <= n / i && n >= (long long) divisor.size(); ++i) {
      if (n % i) continue;
      res.emplace_back(i);
      while (n % i == 0) n /= i;
    }
    if (n >= (long long)divisor.size()) {
      res.emplace_back(n);
    } else {
      while (n > 1) {
        long long d = divisor[n];
        res.emplace_back(d);
        while (n % d == 0) n /= d;
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
};

int main() {
  Prime prime(1000000);
  array<int, 1000000> sum;
  sum[0] = 0;
  for (int i = 1; i < 1000000; ++i) sum[i] = sum[i - 1] + prime.isPrime(i);
  int n;
  while (cin >> n) cout << sum[n] << endl;
}

C++: #include <iostream>
using namespace std;
 
bool isprime(int n) { //??´????°?????????°true
    for(int i=2; i*i <= n; i++) {
        if(n%i==0) return false;
    }
    return n != 1;
}
 
int main() {
int n;
while(cin >> n) {
int cnt = 0;
for(int i=2; i<=n; i++) if(isprime(i)) cnt++;
cout << cnt << endl;
}
return 0;
}

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

bool isPrimeNumber(const unsigned long n);

int main(){
    unsigned long n;
    while(cin>>n){
        unsigned ans = 0;
        for(unsigned long i=n;i>0;i--){
            if(isPrimeNumber(i)){
                ans++;
            }
        }
        cout << ans << endl;        
    }
}

bool isPrimeNumber(const unsigned long n){
    static const unsigned long carn[]{
        561,	1105,	1729,	2465,	2821,	6601,	8911,
        10585,	15841,	29341,	41041,	46657,	52633,	62745,	63973,	75361,
        101101,	115921,	126217,	162401,	172081,	188461,	252601,	278545,	294409,
        314821,	334153,	340561,	399001,	410041,	449065,	488881,	512461,	530881,
        552721,	656601,	658801,	670033,	748657,	825265,	838201,	852841,	997633,
        1024651,1033669,1050985,1082809,1152271,1193221,1461241,1569457,1615681,
        1773289,1857241,1909001,2100901,2113921,2433601,2455921,2508013,2531845,
        2628073,2704801,3057601,3146221,3224065,3581761,3664585,3828001,4335241,
        4463641,4767841,4903921,4909177,5031181,5049001,5148001,5310721,5444489,
        5481451,5632705,5968873,6049681,6054985,6189121,6313681,6733693,6840001,
        6868261,7207201,7519441,7995169,8134561,8341201,8355841,8719309,8719921,
        8830801,8927101,9439201,9494101,9582145,9585541,9613297,9890881
    };

    if(n==2)
        return true;
    else if(n<2||n%2==0)
        return false;
    else{
        for(unsigned long i=0;i<sizeof(carn)/sizeof(carn[0]);i++){
            if(n<carn[i])
                break;
            if(n==carn[i])
                return false;
        }
        for(unsigned long i=n-1;i>0;i--){
            if(fmodl(powl(i,n),n)!=i)
                return false;
        }
        return true;
    }
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

bool t[1000000];

int main(){
	memset(t,1,sizeof(t));
	t[0] = t[1] = false;
	for(int i = 2; i < 1000; i++){
		if(t[i])
			for(int j = 2 * i; j < 1000000; j += i){
				t[j] = false;
			}
	}

	int n;
	while(cin>>n){
		int ans = 0;
		for (int i = 0; i <= n; i++)
		{
			ans += t[i];
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  vector<int> v;
  while (cin >> n) {
    if (v.size() > n) {
      cout << accmulate(v.begin(), v.end() - (v.size() - n), 0) << endl;
    }
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,i,j;
    int ans;

    while(cin >> n){ 
        ans=0;
        for(i=2;i<=n;i++){
            for(j=2;j<=i;j++)
                    if(i%j==0){
                        
                        //nの因数iが素数かどうかを判定する
                        //割り切れたら素数じゃないのでループ抜ける
                        
                        break;

            }
                    //jが最終まで行けばiが素数なのでans++
                    if(j==i)ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int n;
int a[1000000];
int ans;

int main()
{
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            if(i == 2 || i == 3 || i == 5 || i == 7)ans++;
            if(i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0)ans++;
        }
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

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

C++: #include<memory.h>
#include<cstdio>
const int maxn=100000;
int x;
bool isPrime[maxn];
void generateprime()
{

    memset(isPrime,true,sizeof(isPrime));
    for(int i=2;i<maxn;i++)
        for(int j=2;j*i<maxn;j++)
        isPrime[j*i]=false;
}

int main()
{
    generateprime();
    while(scanf(" %d",&x)!=EOF)
    {   int res=0;
        for(int i=2;i<=x;i++)
            if(isPrime[i])
            {
            res=res+1;}
        printf("%d\n",res);
    }
}