Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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;
	}
}

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

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(scanf("%d",&n)!=EOF){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

  if(n%2==0)
    return false;

  else{
    for(int i=3; i<n; i++){
      if(n%i == 0)
	return false;
    }
  }

  return true;
}

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

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

const int MAXN = 1000005;
int num[MAXN];

int main() {
  for(int i = 0; i < MAXN; ++i) {
    num[i] = isPrime(i);
  }
  for(int i = 1; i < MAXN; ++i) {
    num[i] += num[i-1];
  }
  int n;
  while(cin >> n) {
    cout << num[n] << endl;
  }
  return 0;
}

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

int main() {
    bool is_prime[N];
    is_prime[0]=is_prime[1]=false;
    for (int i=2; i<N; i++) {
        is_prime[i]=true;
    }
    for (int i=2; i*i<N; i++) {
        if (is_prime[i]) {
            for (int j=i*i; j<N; j+=i) {
                is_prime[j]=false;
            }
        }
    }
    int n[N];
    int count=0;
    for (int i=0; i<N; i++) {
        if (is_prime[i]) {
            count++;
        }
        n[i]=count;
    }
    while (true) {
        int x;
        cin >> x;
        if (cin.eof()) {
            break;
        }
        cout << n[x] << endl;
    }
    return 0;
}

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

int main(){
	int i, j, n, num = 0, count = 0;

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

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool IsPrime(int n)
{
	int s = floor(sqrt(n)+0.5);
	for(int i = 2;i<=s;i++)
		if(n%i==0)return false;
	return true;
}
const int maxn = 1000000;
bool ar[maxn];
int dp[maxn];
int main()
{
	for(int i = 2;i<=maxn;i++)
		if(IsPrime(i))ar[i] = true;
	for(int i = 1;i<=maxn;i++)
		if(ar[i])dp[i] = dp[i-1]+1;
		else dp[i] = dp[i-1];
	int n;
	while(cin >> n)
		cout << dp[n] <<endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,i,j;
	int time_sum = 0;
	int a[100000];
	while (cin >> n)
	{
		if (time_sum == 29) break;
		time_sum = time_sum + 1;
		int sum = 0;
		for (i = 2; i <=n; i++)
			a[i] = 1;
		for (i = 2; i <=n; i++)
		{
			if (a[i])
				for (j = i + i; j <=n; j = j + i)
					a[j] = 0;
		}
		for (i = 2; i <=n; i++)
		{
			if (a[i]) sum = sum + 1;
		}
		cout << sum << endl;
	}
	return 0;

}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,n;
    while ( cin >> a){
        n=0;
        for (int i=2;i<a;i++){
            if (prime(i)==0){
                n++;
            }
        }
        cout << n << endl;
    }
}


int prime(int x){
    if(x==2 || x==3)
        return 0;
    if(x%2==0)
        return 1;
    for (int i=3;i<=sqrt(x)+1;i+=2){
        if(x%i==0)
            return 1;
    }
    return 0;
}

C++: #include <iostream>
#include <complex>
int main(){
	while(1){
		int ans=0;
		int n;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			std::cout<<0<<std::endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=11){
				for(int i=11;i<=n;i+=2){
					bool prime=true;
					int iSqrt=sqrt(i);
					for(int k=3;k<=iSqrt;k+=2){
						if(i%k==0){
							prime=false;
							break;
						}
					}
					if(prime)ans++;
				}
			}
		std::cout<<ans<<std::endl;
		}
	}
}

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

int main(){
  bool prime[1000000] = {};
  int sum[1000000]; sum[0] = sum[1] = 0;
  for(int i = 2 ; i < 1000000 ; i++ ){
    sum[i] = sum[i - 1];
    if(!prime[i]){
      for(int j = i + i ; j < 1000000 ; j += i ){
        prime[j] = true;
      }
      sum[i]++;
    }
  }

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

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

using namespace std;

vector<int> ps;

int isprime(int n){
	vector<int>::iterator it;
	for(it=ps.begin();it!=ps.end();it++){
		if(n%(*it) == 0) return 0;
	}
	ps.push_back(n);
	return 1;
}

int main(){
	int n;
	scanf("%d", &n);

	int c=0;
	for(int i=2;i<=n;i++)
		if(isprime(i)) c++;

	printf("%d\n", c);
}