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 <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;

int n;
const int maxn = 10000000;
bool is[maxn];
int sum;
void f()
{
    memset(is , true , sizeof(is));
    is[0] = is[1] = false;
    int m = sqrt(maxn);
    for(int i = 2 ; i <= m ; i ++)
    {
        if(is[i])
        {
            for(int j = i * i ; j <= maxn ; j += i)
                is[j] = false;
        }
    }
}


int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    f();
    while(cin >> n)
    {
        sum = 0;
        for(int i = 0 ; i <= n ; i ++)
        {
            if(is[i])
                sum ++;
        }
        cout << sum << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

bool hurui[1000010];
int dp[1000010];

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

int main(){
    
    REP(i,1000010)hurui[i]=true;
    hurui[0]=hurui[1]=false;
    for(int i=2;i<=1000005;i++){
        if(hurui[i]){
            if(isPrime(i)){
                for(int j=i+i;j<=1000005;j+=i)hurui[j]=false;
            }
        }
    }
    
    REP(i,1000005)dp[i+1]=dp[i]+(hurui[i+1]?1:0);
    
    int t;
    while(cin>>t){
        cout<<dp[t]<<endl;
    }
    
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
	vector<int> isPrime;
	
	while(cin>>n)
	{
		for(int i = 0; i < n; i++){
			isPrime.push_back(1);
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
//			printf("head:%d    fin:%d\n",head,fin);
			
			if(fin < head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
			}
		}
		printf("%d\n",cont);
	}
}

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

int x[1000000];

int solve(int b){
    int m = 0;
    if(b == 1){
        return 0;
    }else if(b==2){
        return 1;
    }
    x[m++] = 2;
    for(int i=3;i<=b;i+=2){
        bool a = true;
        for(int j=0;j<m;j++){
            if(i%x[j]==0){
                a = false;
                break;
            }
        }
        if(a){
            x[m++] = i;
        }
    }
    return m;
}

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

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

long long int n,p[1000010],j=0,a;
int main(){
	bool isp[1000010];							  
	for(int i=0;i<=1000009;i++){
		isp[i]=true;
	}
	isp[0]=false;
	isp[1]=false;
	for(int i=2;i<=1000010;i++){
		if(isp[i]){
			p[j]=i;
			for(int k=i*2;k<1000010;k+=i){
				isp[k]=false;
			}
		}
	}
	while(cin>>n){
		a=0;
		for(int i=1;i<=n;i++){
			if(isp[i])a++;
		}
		cout<<a<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;
	
	while(cin >> n){
		bool prime[1000000] = {false};
		prime[1] = true; //1???????????\
		
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

C++: #include<cstdio>
using namespace std;
bool us[1000010]={false};
int p[1000010] = {0};
int main(){
    /*Eratosthenes*/
    p[0] = 2;
    for(int i = 0; i <= 1000010; i+=2){
        us[i] = true;
    }
     
    int cnt = 1;
    for(int i = 3; i <= 1000010; i+=2){
        int q = 0;
        if(us[i] == true)continue;
        else if(us[i] == false){
            p[cnt] = i;
            cnt++;
            us[i] = true;
            q = i;
            for(int j = q+q; j <= 1000010; j += q){
                us[j] = true;
            }
        }
    }
     
    int n;
    while(~scanf("%d",&n)){
        int x = 0;
        while(1){
            if(p[x] > n)break;
            x++;
        }
        printf("%d\n",x);
    }
    return 0;
}

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

int main()
{
	int count=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<0<<endl;
		}

		else{
		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				count++;
		}
		printf("%d\n",count);
		count=1;}
	}
}

C++: #include<stdio.h>
int main()
{
    long long n;
    while(scanf("%lld",&n)==1)
    {
       long long i,j,k,s=0;
       for(i=2;i<=n;i++)
    {
        k=0;
      for(j=2;j*j<=i;j++)
      {
          if(i%j==0)
          {
              k=1;
              break;
          }
      }
       if(k==0)
          {
             ++s;
          }
    }
        printf("%lld\n",s);
    }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

static int GetPrimeNumberNum(int maxValue);

int main(void)
{
  int n;
  
  while (std::cin >> n) {
    std::cout << GetPrimeNumberNum(n) << std::endl;
  }
}

static int GetPrimeNumberNum(int maxValue)
{
  std::vector<int> searchList;
  std::vector<int> primeList;
  
  for (int i = 2; i <= maxValue; i++) {
    searchList.push_back(i);
  }
  
  double maxValueSq = sqrt((double)maxValue);
  
  while (true) {
    int newPrime = searchList.at(0);
    
    if (newPrime > maxValueSq) {
      break;
    }
    
    primeList.push_back(newPrime);
    
    for (std::vector<int>::iterator it = searchList.begin();
         it != searchList.end();
         ) {
      if (*it % newPrime == 0) {
        it = searchList.erase(it);
      }
      else {
        ++it;
      }
    }
  }
  
  for (std::vector<int>::iterator it = searchList.begin();
       it != searchList.end();
       ++it) {
    primeList.push_back(*it);
  }
  
  searchList.clear();
  
  return primeList.size();
}