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 <cstdio>
#define MAX 999999
using namespace std;

int main(void){
  int num,cnt;
  bool is_prime[MAX];

  for( int i = 0 ; i <= MAX ; i++ ) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;

  for( int i = 2 ; i*i <= MAX ; i++ ){
    if( is_prime[i]){
      for( int j = 2*i ; j <= MAX ; j += i ){
	is_prime[j] = false;
      }
    }
  }

  while(scanf("%d" ,&num) != EOF){
    cnt = 0;
    for( int i = 2 ; i <= num ; i++ ){
      if( is_prime[i] ) cnt++;
    }
    cout << cnt << endl;

  }
  return 0;
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int list[100000];

    cnt=0;
    for (int i=0; i<1000000; i++){
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (int i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        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 <iostream>
#include <cmath>

int prime[1000000];


bool isPrime(int n) {
  int x = sqrt(static_cast<double>(n));
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include<math.h>
int main(){


   long long int i, j ,n,c,k,p;
   while(scanf("%lld",&n)==1){
        k=0;
    for(i=2;i<=n;i++){
            c=0;
        for(j=2;j<=sqrt(i);j++){
        if(i%j==0)c++;}
        if(c==0){


                k++;}
    }
         printf("%lld\n",k);
   }
return 0;
}

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

#define MAX_MAX 1000010

using namespace std;

bool isChecked[MAX_MAX];
vector <int> prime;

int CountPrimeNum(int max) {
	
	int count = 0;
	for (int i = 0; i < MAX_MAX; i++) {
		if (prime[i] > max) break;
		count++;
	}	
	return count;
}


int main() {
	for(int i = 0; i < MAX_MAX; i++) {
		isChecked[i] = false;
	}
	
	isChecked[0] = true;
	isChecked[1] = true;
	
	for (int i = 2; i < MAX_MAX; i++) {
		if(isChecked[i]) continue;
		
		prime.push_back(i);
		
		for (int j = 1;j * i < MAX_MAX;j++) {
			isChecked[i*j] = true;
		}
	}
	
	int n;
	while(cin >> n) {
		cout << CountPrimeNum(n) << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	
	while(scanf("%d", &n) != EOF){
	
	bool *d = new bool [n+1];
	int count = 0;

	for(int i = 0; i <= n; i++)
		d[i] = true;

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


	return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void init(){
	for(int i=2;i<999999;i++){
		bool isprime=true;
		for(vector<int>::iterator p(prime.begin());p!=prime.end();p++){
			if((*p)*(*p)>i)break;
			if(i%*p==0){
				isprime=false;
				break;
			}
		}
		if(isprime){
			prime.push_back(i);
		}
	}
}
int main(){
	int n;
	init();
	while(cin>>n){
		cout<<lower_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n[99999],j,o=0;
	for(int i=2;i<=99999;i++){
		n[i]=1;
		
	}
	n[0]=n[1]=0;
		for( j=2;j<=99999;j++){
			if(n[j]){
				for(int k=j*2;k<=9999;k+=j){
				n[k]=0;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
		}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/

int prime[1000000];
bool is_prime[1000001];

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 (cin >> n)
	{
		cout << sieve(n) << endl;
	}
	
	return 0;
}

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

#define REP(i, N) for(int i = 0; i < N; i++) 

const int N = 1000 * 1000;
int isPrime[1000 * 1000];

int main() {
  REP(i, N) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0; i < N; i++)
    if( isPrime[i] ) {
      for(int j = i + i; j < N; j += i)
        isPrime[j] = false;
    }

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

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


int main(void){

	
	int n,count;
	

	while (cin >> n){
		vector <int> list(n+1, 0);

		for (int i = 2; i < n+1; i++){
			list[i] = i;
		}//???????????????????????°???????????????

		//??????????????§?¨???????????????????????????\??£???????????????????´???°?¢????
		for (int i = 2; i < sqrt(n)+1; i++){
			//??????????????\??£??????????´???°???????????????????????????
			if (list[i] == i){//0???????????¢?????§?????°???????????°????????§??????
				//?????????????????????????????§????????°????´???°??§??????
				//????????°????????°???0?????£??\??????
				for (int j = i * 2; j < n+1; j += i){
					list[j] = 0;
				}					
			}
			
				
			}

		count = 0;
		for (int i = 2; i < n+1; i++){
		
			if (list[i] == i){ count++; }

		}cout << count << endl;
		
		
		}//while?????????



	return 0;
}

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

using namespace std;

bool isPrime(int x)
{
	bool is_prime = true;
	if (x == 1) is_prime = false;
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			is_prime = false;
			break;
		}
	}
	return is_prime;
}

int countPrime(int x)
{
	int count = 0;
	for (int i = 2; i <= x; i++)
	{
		if (isPrime(i))
		{
			count++;
		}
	}
	return count;
}

int main()
{
	int n;
	while (cin >> n, !cin.eof())
	{
		cout << countPrime(n) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
			flag=false;
			break;//素数でない時点で打ち切り
			}
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		sosu[i]=(flag)? cnt++ : cnt;		
	}
	//for(int i=0;i<30;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}