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 <stdio.h>
#include <math.h>

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("%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>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

const int N = 100000

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N+1)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

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

#define MAX_N 2000000
int prime[MAX_N];



int main(){
	prime[1] = 1;
	prime[2] = 0;
	prime[3] = 0;
	for(int i = 2; i<=MAX_N;i++){
		if(prime[i] == 0)
			for(int j=2*i;j<=MAX_N;j=j+i)
				prime[j] = 1;
	}
	
	int n;
	int num=0;
	while(true){
		cin >> n;
		if (cin.eof() ==1)
			break;	
		for(int k = 1;k<=n; k++){
			if(prime[k]==0)
				num++;
		}
		cout << num << endl;
		num = 0;
	}
	return 0;
}

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

int main(){
	int n,count;
	bool num[1000000];
	while( scanf("%d",&n) != EOF ){
		for(int i=2;i<=n;i++){
			num[i]=true;
		}
		count = 0;
		for(int i=2;i<=sqrt(n);i++){
			if(num[i]){
				for(int j=i;j<=n;j+=i){
					num[j]=false;
				}
				 count++;
			}
		}
		for(int i=2;i<=n;i++){
			count += num[i];
		}
		printf("%d\n",count);
	}
	return 0;
}

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

const int LIMIT = 1000000;

void eratosthenes(int n, bool *primes);

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    bool primes[LIMIT];
    for (int i = 1; i < LIMIT; ++i)
        primes[i] = false;
    eratosthenes(LIMIT, primes);
    int num_of_primes[LIMIT] = {};
    for (int i = 1; i < LIMIT; ++i) {
        num_of_primes[i] = num_of_primes[i-1];
        if (primes[i])
            ++num_of_primes[i];
    }

    int n;
    while (std::cin >> n) {
        std::cout << num_of_primes[n] << std::endl;
    }
}

void eratosthenes(int n, bool *primes)
{
    primes[2] = true;
    int i = 3;
    double root_n = std::sqrt((double) n);
    while (i <= root_n) {
        if (n % i != 0) primes[i] = true;
        i += 2;
    }
}

C++: #include <iostream>

int main()
{
    bool *table = new bool[1000000];
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        memset(table, 1, sizeof(bool) * (n + 1));
        for (int i = 2; i * i <= n; ++i)
            for (int j = 2; i * j <= n; ++j)
                table[i * j] = false;

        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += table[i];
        std::cout << cnt << std::endl;
    }
    delete[] table;
}

C++: #include <iostream>
using namespace std;
const int MAX_N = 1000000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int eratos(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 && n)
	{
		cout << eratos(n) << endl;
	}
	return 0;
}

C++: 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		vector<int> sos;
		sos.emplace_back(2);
		int s = 1;
		for (int j = 2; j <= n; j++) {
			for (int i = 0; i < sos.size(); i++) {
				if (j%sos[i] == 0) {
					break;
				}
				if (i == sos.size()-1) {
					sos.emplace_back(j);
					s++;
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; i++)
	{
		Counter = Counter + CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (IsPrime(N))
		return 1;

	return 0;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????


	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

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

bool isprime(int n);

int main()
{
	while(1)
	{
		int n,count=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=2;i<n;i++)
		{
			count+=isprime(i)?1:0;
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

bool isprime(int n)
{
	for(int i=2;i<=(int)sqrt(n);i++)
	{
		if(n%i==0)return false;
	}
	return true;
}

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

int main() {
  int cnt[1000000];
  for (int i = 0; i < 1000000; ++i) cnt[i] = 0;
  for (int i = 2; i < 1000000; ++i) {
    bool is_prime = true;
    for (int j = 2; j*j <= i; ++j) {
      if ((i % j) == 0) {
        is_prime = false;
        break;
      }
    }
    cnt[i] = cnt[i-1];
    if (is_prime)
      ++cnt[i];
  }
  int n;
  while(std::scanf("%d",&n) != EOF) {
    std::cout << cnt[n] << std::endl;
  }
  return 0;
}

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


int main()
{

	int i,n,count,num;
	deque<int> sosu;
	deque<int>::iterator it;
	bool flg;
	
	//テーブルを予め作成する
	bool prime[1000000] = {false};
	
	prime[2] = true;

	for( i = 3; i <= 1000000 ; i+=2 ) {
		flg = true;	
		for(it = sosu.begin(); it != sosu.end(); it++ ) {
			num = *it;
			if( i < num * num ){
				break;
			}
			if( (i % num ) == 0 ){
				flg = false;
				break;
			}				
		}
		if( flg == true ) {
			sosu.push_back( i );
			prime[i] = true;	
		}
	}
	
	while(cin >> n){
		count = 0;
		if( n == 2 )
			count = 1;
		else if( n < 2 )
			count = 0;
		else {
			for( i = 3; i <= n ; i+=2 ) {
				if( prime[i] == true )
					count++;
			}
			count ++;
		}
		cout << count << endl;
	}
			
	return 0;
}

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


int main(){
	int number,cnt=0;
	cin>>number;
	int* arr = new int[number+1];
	for (int i = 1; i <= number; i+=2)
	{
		arr[i-1]=0;
		arr[i]=1;
	}
	for (int i = 3; i < sqrt(number); i+=2)
		if (arr[i])
			for (int j = i+i; j <=number; j+=i)
				arr[j]=0;
	arr[2]=1;arr[1]=0;
	for (int i = 0; i <= number; i++)
		if (arr[i])
			++cnt;
	cout<<cnt<<endl;
}