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++: // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
// #define DEBUG
#ifdef DEBUG
#define debug(...) printf( __VA_ARGS__ )
#else
#define debug(...)
#endif
#define MEM(x,y) memset(x, y,sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
vector<int> vec;
int a[999999 + 10];
void init(){
	memset(a,0,sizeof a);
	for (int i = 2;i <=  999999 + 9;++i){
		if (a[i] == 0){
			vec.push_back(i);
			for (int j = i + i;j <=  999999 + 9;j += i){
				a[j] = 1;
			}
		}
	}
}
int main()
{	
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int n;
	init();
	while(scanf("%d",&n) != EOF){
		int ans = upper_bound(vec.begin(), vec.end(),n) - vec.begin();
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  int ans,n;
  while (cin >> n) {
    for(int i=2;i<n+1;i++) {
      for(int j=2;j<i+1;j++) {
        if(i == j) {
          ans++;
          break;
        }
        if(i % j ==0) {
          break;
        }
      }


    }
    cout << ans << endl;
    ans = 0;
  }
}

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

int main()
{
  bool p[1000001];
  int n, ans;

  for(int i=0; i<=1000000; i++){
    p[i] = (i<=1)? false : true ;
  }

  for(int i=2; i<=sqrt(1000000)+1; i++){
    if(p[i]){
      for(int j=i*2; j<=1000000; j+=i){
        if(j%i == 0)
        p[j] = false;
      }
    }
  }

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

C++: #include<stdio.h>
int main() {
	int n,i,k,ans;
	int MAX_V=1000000;
	int prime[MAX_V];
	int sum[MAX_V+1];
	for(i=2;i<=MAX_V;i++) {
		prime[i]=1;
	}
	for(i = 2; i*i <= MAX_V; i++) { 
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	while(scanf("%d", &n) != EOF) {
		for(i=0;i<=n;i++) {
			sum[i+1]=sum[i]+prime[i];
		}
		ans=sum[n+1];
		printf("%d\n",ans);
	}
	return 0; 
}

C++: #include <iostream>
#define REP(i,n) for(int (i) = 0; i <= n; ++i)
using namespace std;

bool is_prime(int n){
    for (int i = 2; i*i <= n; i++) if(n%i == 0)return false;
    return n>=2;
}

int main() {
    int n;
    while(cin>>n){
        int ret = 0;
        REP(i, n)if(is_prime(i))ret++;
        cout<<ret<<endl;
    }
    return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		int num = 0;
		for (int i = 1; i <= n; i++) {
			if (i <= 3) {
				if (i == 2 || i == 3) num++;
				continue;
			}
			else {
				if (i % 2 == 0 || i % 3 == 0) continue;
				if (i % 6 != 1 && i % 6 != 5) continue;
				bool check = true;
				for (int j = 5; j * j <= i; j += 6) {
					if (i % j == 0) check = false;
					if (i % (j + 2) == 0) check = false;
					if (check == false) break;
				}
				if (check == true) num++;
			}
		}
		cout << num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

bool isPrime(int num);

int main()
{
	int count = 0;
	/*int m = 2, n = 0, num;

	cin >> num;

	int *data = new int[num + 1];
	int *result = new int[num + 1];

	data[0] = 0;
	data[1] = 0;

	do
	{
		for (i = 2 * m; i < num + 1; i += m)
		{

		}
	}
	while
	{

	}*/
	const int N = 1000;
	std::vector<bool> isPrime(N + 1, true);    // ?´???°????????°?????¨??¨ON???
	for (int i = 2; i < N; ++i) {
		if (isPrime[i])
		{   
			count++;

			for (int k = i + i; k <= N; k += i)
				isPrime[k] = false;      // ?´???°????????°????´???°????????°?????¨???OFF???
		}
	}
	return 0;






	
}

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n) != EOF) {
		res = 0;
		while (!Eratos[n]) {
			n--;
		}
		printf("%d\n",Eratos[n]);
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vi prime_count;
void sieve(int max){
    int count = 0;
    vector<bool> table(max + 1, true);
    table[0] = false;
    prime_count.push_back(0);
    table[1] = false;
    prime_count.push_back(0);
    for(int i = 2; i <= max; i++){
        if(table[i]){
            count++;
            for(int j = 2; i * j <= max; j++){
                table[i * j] = false;
            }
        }
        prime_count.push_back(count);
    }
}

int main(){
    int n;
    sieve(1000000);
    while(cin>>n){
        cout << prime_count[n] << endl;
    }
    return 0;
}

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

using namespace std;

const int MAX_N = 1000000;

int N;

int len;
bool isPrime[MAX_N];
int num[MAX_N];				//the number of prime less than i

void sieve(){
	//init
	fill(isPrime, isPrime + MAX_N, true);
	isPrime[0] = isPrime[1] = false;
	num[0] = num[1] = 0;
	for(int i = 2; i < MAX_N; i ++){
		if(isPrime[i]){
			num[i] = num[i - 1] + 1;
			for(int j = 2 * i; j < MAX_N; j += i)
				isPrime[j] = false;
		}
		else{
			num[i] = num[i - 1];
		}
	}
}

int main(int argc, char const *argv[]){

	sieve();
	while(scanf("%d", &N) != EOF){
		printf("%d\n", num[N]);
	}

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
while(~scanf("%d",&n)){
int* table =  new int[n+1];
fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i*i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

C++: #include <stdio.h>

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}