Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

const int MAX_N = 1e6+5;
int prime[MAX_N];
bool is_prime[MAX_N];

int seive(int n) {
  rep(i, 0, MAX_N) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;

  int p = 0;

  rep(i, 2, n+1) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
    }
  }

  return p;
};

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

  int n;
  while (cin >> n) {
    cout << seive(n) << 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 += 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<bits/stdc++.h>
using namespace std;

int main(){
  int n,i;
i=0;
vector<int> an(1000000),as(1000000);
an[0]=2;
  for(int j=3;j<1000000;j++){
   for(int u=0;u<1000000;u++){
if(an[u]==0){
an[u]=j;
break;
}
if(j%an[u]==0){
break;
}
else{
continue;
}
}
}
   for(int u=1;u<1000000;u++){
if(u==an[i]){
as[u]=as[u-1]+1;
}
else{
as[u]=as[u-1];
}
}
for(int i=0;i<30;i++){
   cin>>n;
cout<<as[n]<<endl;
}
}

C++: #include<stdio.h>
 int prime[1000000];
 int main(){ prime[0]=-1; 
prime[1]=-1; for(int i=2;i<1000000;i++){
 if(prime[i]==0){ prime[i]=1;
 for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
 } 
} 
int now;
 while(~scanf("%d",&now)){ 
int ans=0; for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
 printf("%d\n",ans); 
}
 }

C++: #include <iostream>
#include <cmath>
using namespace std;
const int maxn = 1000000;
int dp[maxn];
bool ar[maxn];
int main()
{
	for(int i = 2;i<=maxn;i++)
	{
		if(!ar[i])
		{
			for(int j = 2;j*i<maxn;j++)
				ar[i*j] = true;
		}
		dp[i] = dp[i-1] + !ar[i];
	}
	int n;
	while(cin >> n)
		cout << dp[n] <<endl;
	return 0;
}

C++: #include <stdio.h>

bool mark[1000000];
void init() {
	for(int i=0; i < 1000000; i++) mark[i] = false;
	
	mark[0] = true;
	mark[1] = true;
	for(int i = 2;i < 1000000;i++)
	{
		if(mark[i])
			continue;
		for(int j = i * 2; j < 1000000; j += i)
		{
			mark[j] = true;
		}
		
	}

}
int main() {
	init();
	int n, count=0;
	//if(freopen("D:\\test.txt", "r", stdin) == NULL) return -1;
	while(scanf("%d", &n) != EOF) {
		for(int i = 2; i <= n;i++)
		{
			if(!mark[i])
			{
				count++;
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
    long long n;

    while (scanf("%lld", &n) != EOF){
        int cnt = 0;
        for (int i = n; i >= 2 ; i--){
            for (int j = 2; j < i; j++){
                if (i % j == 0){
                    //printf("%d\n", i);
                    cnt++;
                    break;
                }
            }
        }
        printf("%d\n", n - 1 - cnt);
    }

    return (0);
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n){
    int i;
        i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)  return false;
            i += 2;
        }
    return true;
}
 
int main(void){
    int n, i, cnt;
    while(cin >> n){
        cnt = 1;
        for(i = 3; i <= n; i = i + 2){
            if(isPrime(i))  cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

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

inline int isPrime(int x){
  if(x<=1)return 0;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return 0;
  }
  return 1;
}

int p[1001000];
int main(){
  for(int i=1;i<1000000;i++){
    p[i] = p[i-1] + isPrime(i);
  }

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

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	int premaxin=1;


	for(i=0;i<100000;i++){
		c[i]=1;
		data[i]=0;
	}
	c[0]=c[1]=0;

	while(scanf("%d",&n)!=EOF){

		if(premaxin<n){
			for(i=0;i<=n;i++){
				if(c[i]==1){
					if(premaxin>i){
						j=premaxin;
					}else{
						j=i+1;
					}
					for(;j<=n;j++){
						if(j%i==0){
							c[j]==0;
						}
					}
				}
			}

			count=data[premaxin];
			for(i=premaxin+1;i<=n;i++){

				if(c[i]==1){
					count++;
				}
				data[i]=count;
			}
		}

		printf("%d\n",data[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 int n, i, j, k;
 int b;
 int count = 0;
 
 

 while(cin >> n){
  int a[n+1];
  for(i = 2;i < n+1;i++){
    a[i] = i;
  }


  for(i = 2;i*i < n+1;i++){
    if(a[i] != 0){
      b = a[i];
     }
    for(j = 2;j*b < n+1;j++){
      a[j*b] = 0;
    }
  }
  for(i = 2;i < n+1;i++){
    if(a[i] != 0){
      count++; 
    }
  }
  cout << count << endl;
  count = 0;
  
  
 }

 return 0; 
}

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


using namespace std;

int main(){
	int n;
	
	while(cin>>n){
		vector<int> prime(n);
		int ptr=0;
		if(n<=3){
		switch(n){
		case 0:
		case 1: ptr=0; break;
		case 2: ptr=1; break;
		case 3: ptr=2; break;
		}
		}
		else{
			prime[ptr++]=2;
			prime[ptr++]=3;
		
		for(int no=5;no<=n;no+=2){
			int flag=0;
			for(int i=1;prime[i]*prime[i]<=no;i++){
		if(no%prime[i]==0){
				flag=1;
				break;
		}
	}
	if(!flag)
		prime[ptr++]=no;
	}
		}
		cout<<ptr<<endl;
	}
	
	
	
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

int main()
{
	int n;

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