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 <iostream>
#include <string>
#include <vector>

#include <math.h>

using namespace std;

static inline bool judge_prime(const int num) {
	if (num < 2) {
		return false;
	}
	else if (num == 2) {
		return true;
	}
	else if (num % 2 == 0) {
		return false;
	}
	else if (num == 3) {
		return true;
	}

	if (num % 3 == 0) {
		return false;
	}

	if(num % 6 != 1 && num % 6 != 5) {
		return false;
	}

	const double sqrtnum = sqrt(num);
	for(int i = 5; i <= sqrtnum; i += 6) {
		if(num % i == 0) {
			return false;
		}
		if (num % (i + 2) == 0) {
			return false;
		}
	}
	return true;
}

static int count_prime(const int input) {
	int counter_prime = 0;

	for (int i = input; 1 < i; i --) {
		if (judge_prime(i)) {
			counter_prime ++;
		}
	}
	return counter_prime;
}

int main() {
	int input;
	while(cin >> input) {
		cout << count_prime(input) << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;	
	while(cin >> n){
		bool prime[n];
		prime[n] = {false};
		prime[1] = true;
		
		// ??¨??????????????????????????????
		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<iostream>
#define N 999999
#define FOR(i,a,b) for( int i = ( a ); i < ( b ); i++ )
#define WHILE(n) while( std::cin >> n )
int p[(N+1)/2];int m[N+1];int mk();int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();WHILE(n){cout<<m[n]<<i'\n';}return 0;}int mk(){int i,j,e=1;REP(i,3,N_MAX){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;tag:m[i]=e;}}

C++: #include<cstdio>
int sosu[1000000]={};
bool f[1000000]={false};
int main(){
  sosu[2] = 1;
  for(int i=3;i<=999999;i+=2){
    if(!f[i]){
      f[i] = true;
      if(i >= 1000) continue;
      for(int j=i*i;j<=999999;j+=i) f[j] = true;
      sosu[i] = 1;
    }
    sosu[i] += sosu[i-1];
    sosu[i+1] += sosu[i];
  }
  int n;
  while(scanf("%d",&n)!=EOF) printf("%d\n",sosu[n]);
  return(0);
}

C++: #include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V+1],sum[MAX_V+2]={0};
int main(){
  int n;
  for(int i = 2;i <= MAX_V;i++){
    prime[i] = 1;
  }
  for(int i = 2;i * i <= MAX_V;i++){
    if(prime[i]){
      for(int k = 2* i;k <= MAX_V;k += i)
      prime[k]=0;
    }
  }
  for(int i = 2;i < MAX_V;i++){
    sum[i] +=sum[i-1]+prime[i];
  }
  while(scanf("%d",&n)!=EOF){
    printf("%d\n",sum[n]);
  }
  return 0;
}

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

bool isPrime(unsigned int n);

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

    return 0;
}

bool isPrime(unsigned int n)
{
    if( n==0 || n==1 ) return false;
    if( n==2 ) return true;
    if(!(n%2)) return false;
    
    int rn = static_cast<int>(sqrt(n));
    
    bool flag = true;
    for(int i=3; i<=rn; i+=2){
        if(!(n%i)){
            flag = false;
            break;
                }
    }
    return flag;
}

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

using namespace std;
bool IsPrime[1000000];
vector<int> Prime;

void calc()
{
	for(int i = 0; i < 1000000; ++i)
	{
		IsPrime[i] = true;
	}
	for(int i = 2; i < 1000000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 1000000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	calc();
	int n;
	cin >> n;
	int count = 0;
	int a = Prime.size() - 1;
	while(Prime[count] <= n)
	{
		if(count >= a)
		{
			break;
		}
		count++;
	}
	cout << count << endl;
}

int main()
{
	solve();
	return(0);
}

C++: #include <bits/stdc++.h>
using  namespace std;
#define ll    long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define mpi     map<int,int>
#define mps     map<string,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>
#define MAX      10000010
bool prime[MAX];
void seive(){
memset(prime,true,sizeof(prime));
prime[0]=prime[1]=false;
for(int p=2;p*p<=MAX;p++){
       if(prime[p]){
    for(int i=p*p;i<=MAX;i+=p){
       prime[i]=false;
    }
}

}
}
int main(){
seive();
ll n;
int c=0;
while(cin>>n){
 for(int i=2;i<=n;i++){
   if(prime[i]){
    c++;
   }
 }
 cout<<c<<endl;
 c=0;
}

}

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

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

int main(){
	int n;
	
	while(cin >> n){
		int a=0;
		for(int i = 1; i <= n; ++i){
			if(prime(i))++a;
	}
		cout << a << '\n';
	}
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i<= MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i *i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	
	int n, m;
	while (cin >> n>>m){
		if (n==m) cout <<0 << endl;
		else {

		}
	}
	return 0;
}

C++: j,a['   '],s;main(i){for(;++i<1e6;){if(!a[i])for(j=i;j<1e6;)a[j+=i]=1;a[i]=s+=!a[i];}for(;~scanf("%d",&i);printf("%d\n",a[i]));}

C++: #include<iostream>
#include<string>
int main(){for(int m,n,o,c,d,e,i;!(std::cin>>n).eof();){if(n<3)e=n>1;else{bool*v=new bool[c=(n&1?n:--n)/2+1];memset(v,1,c);for(i=m=e=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;e++;for(d=o=m*2+1;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(i=1;i<c;)e+=v[i++];delete[]v;}printf("%d\n",e);}}

C++: #include<iostream>
using namespace std;
int main(){
	long long int N,count=0;
	while(cin >> N){
		count = 0;
		if(N<0)	break;
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
	}
	return 0;
}

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

int sosu(long x){
	int a=1;
	long b,c,d;
	d=sqrt(x);
	for(b=3;b<=d;b=b+2){
		c=x%b;
		if(c==0){
			a=0;
			break;
		}
	}
	return (a);
}

int main(void){
	int y,z;
	long i,j,k,n;
	long f[168];
	j=0;
	for(i=3;i<=10000;i=i+2){
		if(sosu(i) == 1){
			f[j]=i;
			j++;
			if(j==168)break;
		}
	}
	for(i=0;i<168;i++){
//		printf("%ld\n",f[i]);
	}
	while(scanf("%d",&n) != EOF){
		z=1;
		for(i=3;i<=n;i=i+2){
			y=1;
			for(j=0;j<168;j++){
				if(i==f[j]) break;
				else k=i%f[j];
				if(k==0){
					y=0;
					break;
				}
			}
			z=z+y;
		} 
		if(n==1) printf("0\n");
		else printf("%d\n",z);
	}
	return 0;
}

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

#define N 1000000

int main() {
    int n;
    bool prime[N+1];
    int count[N];
    for(int i=2; i<N; i++){
        prime[i] = true;
    }
    for(int i=2; i<N; i++){
        if(prime[i]){
            count[i] = count[i-1]+1;
            if(i<1000){
                for(int j=i*2; j<N; j+=i){
                    prime[j] = false;
                }
            }
        }else{
            count[i] = count[i-1];
        }
    }
    
    while(cin >> n){
        cout << count[n] << endl;
    }
    return 0;
}