Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false


int prime[100000]={0};
int k=1;
void
 makeprime(int n)
{
    prime[0]=2;
    for (int i = 3; i < n; i++)
    {
        double temp = sqrt(i);
        for (int j = 0;; j++)
        {
            if (i % prime[j] == 0)
            {
                break; //this is no prime.
            }
            if (temp < prime[j])
            {
                prime[k++]=i;
                break;
            }
        }
    }
}

int main()
{
    makeprime(999999);
    
    int n;
    int ans=0,i;
    while(cin>>n){
        ans=0;
        i=0;
        while(true){
            if(prime[i]<=n){
                ans++;
            }
            if(n<prime[i]){
                break;
            }
            i++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
int a[1000000]{};
bool b[1000000]{};
a[1]=0;
int s=0;
for(int c=2;c<1000000;c++){
	if(!b[c]){
		s++;
		for(int d=c*2;c<1000000;d+=c)b[d]=true;
	}
	a[c]=s;
}
int k;
while(cin>>k){
	printf("%d\n",a[k]);
}
}

C++: #include <iostream>
using namespace std;
const int Max = 10000000;
bool prime[Max];
int main() {
    int in;
    for(int i=0; i<Max; i++) prime[i] = true;
    prime[1] = false;
    for(int i=2; i<Max; i++) {
        if(prime[i]) {
            for(int s=i*2; s<=Max; s+=i) prime[s] = false;
        }
    }
    while(cin >> in) {
        int cnt = 0;
        for(int i=1; i<=in; i++) {
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#define N 999999

using namespace std;

int main(){
  int i, j, n, isFound, count;
  vector<int> data;

  data.push_back(2);
  data.push_back(3);
  for(i=5; i<=N; i+=2){
    for(j=1, isFound=0; data[j]<=sqrt(i); ++j){
      if(i%data[j] == 0){
	isFound = 1;
	break;
      }
    }
    if(isFound == 0) data.push_back(i);
  }

  while(cin >> n){
    for(i=0; i<data.size(); ++i){
      if(n < data[i]) break;
    }
    cout << i << endl;
  }

  return 0;
}

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

int* PrimeCount();

int main()
{
	int n;

	int* a = PrimeCount();

	while (cin >> n) {
		cout << a[n] << endl;
	}

	return 0;
}

int* PrimeCount()
{
	//最大探索値 999999まで
	const int MAX = 1000000;

	//配列全てに1
	array<int, MAX> search;

	for (int i = 2; i < MAX; i++) {
		search[i] = 1;
	}

	for (int i = 2; i < MAX; i++)
	{
		//素数
		if (search[i] == 1)
		{
			//素数の倍数に0
			for (int j = i * 2; j < MAX; j += i)
			{
				search[j] = 0;
			}
		}
	}

	//任意の数字以下での素数の数
	for (int i = 1; i < MAX; i++)
	{
		//1が入ってるとカウントも+1
		search[i] += search[i - 1];
	}

	return &search[0];
}

C++: #include <cstdio>

using namespace std;

int main() {
	long n, m;
	int flag;
	long counter;

	long i, len;
	
    while (scanf("%ld", &n) != EOF) {
        counter = 0;
        m = 2;
        
        while (m <= n) {
            flag = 0;
            len = m / 2;
    
            for(i = 2; i <= len; i++) {
                if(m % i == 0) {
                    flag = 1;
                    
                    break;
                }
            }
    
            if (flag == 0) counter++;
    
            m++;
        }
        
        printf("%ld\n", counter);
    }

    return 0;
}

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

void solve(int n) {
	int i, j, ans = 0;
	for (i = 2; i <= n; i++) {
		int num = 0;
		for (j = 2; j <= i; j++) {
			if (i%j == 0) num++;
		}
		if (num == 1) ans++;
	}
	cout << ans << endl;
}

int main() {
	int n;
	while (cin >> n) {
		cin >> n;
		solve(n);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool array[1000000];
		int count=0;
		array[0]=array[1]=false;
		for(int i=1;i<=n;i++){
			if(array[i]){
				count++;
				for(int j=i*2;j<=n;j+=i){
					array[j]=false;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	while ( cin >> n ){
		bool* table = new bool[ n + 1 ];
		for ( int i = 0; i <= n ; ++i ){
			table[ i ] = false;
		}
		if ( n >= 2 ) table[ 2 ] = true;

		for ( int i = 3; i <= n; i += 2 ){
			table[ i ] = true;
		}
		for ( int i = 3; i <= sqrt( static_cast< double >( n ) ); i += 2 ){
			if ( !table[ i ] ) continue;
			for ( int j = i + i; j <= n; j += i ){
				table[ j ] = false;
			}
		}

		int cnt = 0;
		for ( int i = 0; i <= n; ++i ){
			if ( table[ i ] ) ++cnt;
		}

		cout << cnt << endl;

		delete[] table;
	}
}

C++: #include <stdio.h>
const int MAX_V = 999999;
int main(){
int prime[MAX_V+1]={0};
int sum[MAX_V+2]={0};
int i, k, v ,n;
  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;
      }
    }
  }
  for(i=0 ;i<=MAX_V+1 ;i++){
    sum[i+1] += sum[i] + prime[i];
  }

  while(scanf("%d" ,&n)){
    if(n==0)break;
     printf("%d\n" ,sum[n+1]);
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans=1;
    int num[n+1]={0};
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      if(num[i]!=0) continue;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        for(int j=1; j<=n; j++){
          if(j*i > n) break;
          num[j*i]=1;
        }
        ans++;
      }
    }
    cout << ans << endl;;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int i,j,n;
	
	
	while(cin >> n){
	int count = 0;
	bool flag[n+1];
		
		for(i=2;i<n+1;i++) flag[i] = true;
		
		for(i=2;i<n+1;i++){
			if(!flag[i]){
				continue;
			}
			for(j=2*i;j<n+1;j+=i){
				flag[j] = false;
			}
		}
		
		// 個数を走査
		for(i=2;i<n+1;i++){
			if(flag[i]==true){
				count++;
			}
		}
		
		cout << count << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cmath>
#define Even(n) n%2
using namespace std;

void count_Prime(int n);
bool IsPrime(int num);


int main()
{
	int Data;

	while (cin >> Data)
	{
		count_Prime(Data);
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 1; i <= n; ++i)
	{
		if (IsPrime(i))
			counter++;
	}

	cout << counter << endl;

}

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

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

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