Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int max[30], sol[30], listID=0;
	
    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        min = 1;
        minID = 0;
		printf("check %d ->", n);
        for (int i=0; i<listID; i++){
            if (max[i] < n && min <max[i]){
                min = max[i];
				cnt = sol[i];
            }
        }
		printf("check  %d - %d (cur sols = %d)\n", min+1, n, cnt);
        for (int i=min+1; i<=n; i++){
            if (IsPrime(i)) cnt++;
        }
        max[listID] = n;
        sol[listID] = cnt;
        listID++;
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			if(isprime(i))c++;

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

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

int main(){

	const int N_MAX=100;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		count[i]=so[i]=0;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=1;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]>0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=1;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+1-so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int yakusuu(int i){
	int counter=0;
	for (int j = 1; j <= i; j++){
		if (i%j == 0) counter++;
	}
	return counter;
}


int main()
{
	int n;
	
		
		while (scanf("%d",&n)!=-1)
		{
			int counter1 = 0;
			for (int i = 0; i <= n; i++)
			{
				if (yakusuu(i) == 2) counter1++;
			}

				cout << counter1 << endl;
		}
		
		
	return 0;
}

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_s("%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<iostream>
using namespace std;

int main(){

	bool pn[1000010];
	int sum[1000010] = {0};
	int n;
	
	for(int i = 0; i <= 1000000; i++) {
		pn[i] = true;
	}
	
	pn[1] = false;
	for(int i = 1; i <= 1000000; i++) {
		if(!pn[i]) continue;
		for(int j = 2; i*j <= 1000000; j++) {
			if(pn[i*j]) pn[i*j] = false;
		}
	}
	
	for(int i = 1; i <= 1000000; i++) {
		sum[i] = sum[i-1] + pn[i];
	}
	
	while(cin >> n) {
		cout << sum[n] << endl;
	}

    return 0;
}

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

int main()
{
	int n;
	while(cin >> n)
	{
		int i,j;
		int k = 0;
		for (i=2; i<=n; i++)
		{
			int c=0;
			for(j=1; j<=n; j++)
			{
				if(i%j == 0)
				{
					c++;
				}
			}
			if (c == 2)
			{
				k++;
			}
		}
		cout << k << endl;
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int N = 1000000;
int main(){
	int n;
	vector<bool> v(N,true);
	v[0] = false;
	v[1] = false;
	for (int i=2; i<N; ++i){
		if (v[i] == true){
			for (int j=2*i; j<N; j+=i){
				v[j] = false;
			}
		}
	}
	vector<int> cnt(N);
	for (int i=2; i<N; ++i){
		if (v[i]) cnt[i] = cnt[i-1]+1;
	   else cnt[i] = cnt[i-1];
	}
	while (cin >> n){
		cout << cnt[n] << '\n';
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
    int n,i,k,j,b=0;

    cin >> n;

     for(i=2; i<=n; i++)
    {
        k = 1;
        for(j=2; j<=i/2; j++)
        {
            if(i%j==0)
            {
                k = 0;
                break;
            }
        }

        if(k==1)
        {
            b++;
        }
    }

    cout << b << endl;

    return 0;
}

C++: #include<iostream>
int main() {

  int n,i,j,c;
  while(std::cin>>n){
    c=0;
    int list[n-1];
    for(i=2;i<n+1;i++)list[i-2]=i;
    for(j=2;j*j<n+2;j++)
      if(list[j-2]!=0)
	for(i=1;j-2+list[j-2]*i<n;i++)
	  list[j-2+list[j-2]*i]=0;
    for(i=0; i<n-1; i++)
      if(list[i]!=0)c++;

    std::cout<<c<<"\n";
  }
}

C++: #include <stdio.h>

int main(){
	long sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z,d=0;
	while (scanf("%d", &n) != EOF){
		z = 0;
		if(d < n)
		{for (i = 3; i < n; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++; d = i; }
			}
		}
	}
		for (i = 0; i < n; i++){ if (sosuu[i] > n + 1)break; z++; }printf("%d\n", z);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int i,n,k;
	
	while(cin >> n){
		int flug[n+1];
		int count = 0;
		for(i=0;i<n+1;i++) flug[i] = 1;
		// 0, 1は除外
		flug[0] = flug[1] = 0;
		for(i=2;i*i<n;i++){
			for(k=n;k>=2;k--){
				if((k % i == 0) && (k != i)){
					flug[k] = 0;
				}
			}
		}
		
		// 個数を走査
		for(i=2;i<n+1;i++){
			if(flug[i] == 1){
				count++;
			}
		}
		
		cout << count << endl;
	}
	return 0;
}

C++: while True:
	try:
		n=int(input())
		a=[True]*(n+1)
		a[0]=a[1]=False
		for i in range(2,int(n**0.5)+1):
			if a[i]:
				for j in range(i**2,n+1,i):
					a[j]=False
		print(a.count(True))
	except:
		break

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

using namespace std;

int MAX = 9;

vector <int> v;

int main() {
	int n;
	
	while (cin>>n) {
		v.clear();
		
		for (int i=0; i<=MAX; i++) v.push_back(n-i);
		sort(v.begin(), v.end());
		
		int ans = 0;
		
		for (int i=0; i<=MAX; i++) {
			for (int j=0; j<=MAX; j++) {
				for (int k=0; k<=MAX; k++) {
					if (binary_search(v.begin(), v.end(), i+j+k)) ans++;
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n;
	int count = 1;
	if (n == 1) {
		cout << 0 << endl;
	}
	else if (n == 2) {
		cout << 1 << endl;
	}
	else {
		for (int t = 3; t <= n - 1; t += 2) {
			FOR(i, 1, t - 1) {
				if (t%i == 0) {
					break;
				}
				if (i == t - 1) {
					count++;
					break;
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}