Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int ans=0,math[1000001]={0};
    math[1]=1;
    for(int i=2;i<n+1;i++){
      int bell=i;
      if(math[i]==0){
	ans++;
	math[i]=1;
      }
      while(bell<=n){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      } 
    }
    cout << ans << endl;
  }
}

C++: #include<stdio.h>
#include<math.h>

int sos(int);

int pri[10000000];

int main(){
  int x;
  while(scanf("%d",&x)!=EOF){
    printf("%d\n",sos(x));
  }  
  return 0;
}

int sos(int a){
  int i,j,c=0,b;
  for(j=2;j<=a;j++){
    b=0;
    if(pri[j]==3)continue;
    if(pri[j]==1){c++;continue;}
    for(i=2;i<=sqrt(j);i++){
      if(j%i==0){pri[j]=3;b=1;break;}
      
    }
    if(b==0){pri[j]=1;c++;}
  }
  return c;
}

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

using namespace std;

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

	return true;
}

int main()
{
	int N;

	static int C;

	cin >> N;

	for (int i = 2; i <= N; i++)
	{
		if (isprime(i) == true)
		{
			C += 1;
		}
	}

	cout << C << endl;

	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
bool p[M];
long long int cnt[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  cnt[0] = cnt[1] = 0;
  loop(i,2,M){
    cnt[i] = cnt[i-1] + p[i];
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
  rep(i,10)cout<<cnt[i]<<endl;
}
int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<cnt[n]<<endl;
}

C++: #include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

vector<int> vec;

void makesosuu(void){
	FOR(i, 2, 999999){
		if(i == 2){
			vec.pb(i);
		}else if(i % 2 != 0){
			bool flag = true;
			int j = 3;
			while(j * j <= i){
				if(i % j == 0){
					flag = false;
					break;
				}
				j += 2;
			}
			if(flag) vec.pb(i);
		}
	}
	return;
}

int sosuu(int n){
	int i = 0;
	while(vec[i] < n && i < vec.size()) ++i;

	return i;
}

int main(){
    int n;
    makesosuu();
    while(cin >> n){
        cout << sosuu(n) << endl;   
    }	
}

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

int prime[MAX_N];
bool is_prime[MAX_N];

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

C++: //Prime Number
#include<iostream>
#include<cstdio>

using namespace std;

int main() {
	int n;
	while(cin >> n) {
		int count = 0;
		for(int i = 2; i <= n; i++) {
			bool flag = true;
			for(int j = 2; j <= i/2; j++) {
				if(i % j == 0) {
					flag = false;
					break;
				}
			}
			if(flag == true) {
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <random>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14


using namespace std;

// nまでの素数のリストを作成(nを含む) O(N log long N)
vector<int> make_prime_list(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;

    vector<int> prime_list;
    for (int i = 2; i < n + 1; ++i) {
        if (!is_prime[i]) { continue; }
        prime_list.emplace_back(i);

        for (int j = i; j < n + 1; j += i) {
            is_prime[j] = false;
        }
    }
    return prime_list;
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<int> prime_list = make_prime_list(1000001);

    int n;
    while(cin >> n) {
        int ans = 0;
        for(int i=0;;++i)  {
            if(prime_list[i] <= n){
                ans++;
            }
            else {
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

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

int main(void)
{
	int n;
	bool flag[1000000];
	for(int i=1;i<=999999;i++){
		flag[i]=sosu(i);
	}
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(flag[i])
				ans++;
		}
		cout<<ans<<endl;
	}
}

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

int main() {
	vector<bool>hantei(1000000, true);
	vector<int>sosuu(1000000);
	int s = 0;
	for (int a = 2; a < 1000000; a++) {
		if (hantei[a]) {
			s++;
			for (int b = a * 2; b < 1000000; b += a)hantei[b] = false;
		}
		sosuu[a] = s;
	}
	int c;
	while (cin >> c) {
		cout << sosuu[c] << endl;
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
void cprime(int, int&);

int main() {
	int n;
	
	while (cin >> n) {
		int count = 0;
		for (int i = 0; i < n;i++) {
			cprime(i + 1,count);
		}
		cout << count << endl;
	}
}

void cprime(int n, int& count) {
	if (n == 2) {
		count++;
		return;
	}
	if (n == 1 || n % 2 == 0) return;
	for (int i = 3; i <= sqrt(n);i += 2) {
		if (n % i == 0) return;
	}
	count++;

	return;
}