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

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

C++: #include <cstdio>
#include <iostream>
#define M 1000000

using namespace std;

int main() {

	int c, n;
	bool x[M];

	for(int i=2; i<=M; i++) {
		x[i]=false;
	}
	for(int i=2; i<1000; i++) {
		if(x[i])
			continue;
		for(int j=i*2; j<M; j+=i) {
			if(!x[j])
				x[j]=true;
		}
	}

	while(scanf("%d", &n)!=EOF) {
		c=0;
		for(int i=2; i<=n; i++) {
			if(!x[i])
				c++;
		}
		cout << c << endl;
	}
	

	return 0;

}

C++: #include<iostream>
using namespace std;
int main()
{
    int i=2, j=2, n;
    
    cout<<"Enter a number to print Prime Number: ";
    cin>>n;
    
    cout<<i<<" ";
    
    for(i=2; i<=n; i++)
             for(j=2; j<i; j++)
             {
                      if(i%j == 0)
                      break;
                      else if(i==j+1)
                      cout<<i<<" ";
             }
             
    cout<<endl;
    
    system("pause");
    return 0;
}

C++: #include <iostream>

#define MAX_SIZE 1000000

using namespace std;

void sieve(bool *a) {
    a[0] = a[1] = true;
    
    for(int i = 2;i < MAX_SIZE;i++) {
        if(!a[i]) {
            for(int j = 2;(i * j) < MAX_SIZE;j++) {
                a[i * j] = true;
            }
        }
    }
}

int main() {
    bool not_prime[MAX_SIZE] = { false };
    
    sieve(not_prime);
    
    int n, cnt;
    
    while(cin >> n) {
        cnt = 0;
        
        for(int i = 0;i <= n;i++) {
            if(!not_prime[i]) {
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }
    
    return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


int f(int a){
	if(a==1) return 0;
	for(int i=2;i<=sqrt((double)a);i++){
		if(!(a%i)){
			return 0;
		}
	}
	return 1;
}
bool solve(){
	int n;
	while(cin>>n){
		int cnt=0;
		for(int j=2;j<=n;j++){
			cnt += f(j);
		}	
		cout<< cnt<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

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

int main(){
   int i,j,n,flag=0,x=1;
   int sosu[999];
   sosu[0] = 2;
   cin>>n;
   for(i=3;i<=n;i++){
      flag = 0;
      
      for(j=0;j<x;j++){
         if(i%sosu[j] == 0){
            flag++;
            break;
         }
      }
      if(flag == 0){
         sosu[x] = i;
         x++;
      }
   }
   printf("%d\n",x);
   return 0;
}

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

typedef unsigned int Int;

Int sqrt_prm(const Int& target, Int x = 0) {
	while (x*x < target) {
		x++;
	}
	return x;
}

int main() {
	while (not std::cin.eof()) {
		Int target;
		std::cin >> target;

		std::vector<Int> primes = {};
		Int sqrt = 0;
		for (Int n = 3; n <= target; n+=2) {
			bool flag = true;

			sqrt = sqrt_prm(n, sqrt);
			for (auto&& div : primes) {
				if (n > sqrt) { break; }
				if (n % div == 0) {
					flag = false;
					break;
				}
			}

			if (flag) {
				primes.push_back(n);
			}
		}

		std::cout << primes.size() + (target >= 2 ? 1 : 0) << std::endl;
	}
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	while (scanf("%d", &n) != EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n + 1)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int Max=1000007;

bool visit[Max];
int prime[Max];
int num=0;
void init_prim()
{
    memset(visit, true, sizeof(visit));
    for (int i = 2; i <Max; ++i)
    {
        if (visit[i] == true)
        {
            num++;
            prime[num] = i;
        }
        for (int j = 1; ((j <= num) && (i * prime[j] <= 1000000));  ++j)
        {
            visit[i * prime[j]] = false;
            if (i % prime[j] == 0) break;
        }
    }
}

int main()
{
    int n;
    init_prim();
    while(~scanf("%d",&n))
    {
        int l=lower_bound(prime,prime+num,n)-prime;
        if(prime[l]>n)
            l=l-1;
        printf("%d\n",l);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <stdio.h>
using namespace std;

// Prime Number(0009(
int main()
{
	const int MAX = 1000000 + 1000;
	static bool prime[MAX];
	for (int i = 0; i < MAX; ++i)
		prime[i] = true;
	prime[0] = prime[1] = false;

	for (int i = 2; i < MAX; ++i) {
		if (prime[i]) {
			for (int j = i+i; j < MAX; j += i)
				prime[j] = false;
		}
	}

	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (prime[i])
				++ans;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#define ll long long
using namespace std;
bool status[1000000];
int prime[1000000];
 int N=1000000;
void siv()
{
    int sq=sqrt(N);
    for(int i=4;i<=N;i+=2)status[i]=1;
    for(int i=3;i<=sq;i+=2)
    {
        if(status[i]==0)
        {
            for(int j=i*i;j<=N;j+=i)status[j]=1;
        }
    }
    status[1]=1;
}
void res()
{
    int ans=0;
    for(int i=1;i<=N;i++)
    {
        if(status[i]==0)ans++;
        prime[i]=ans;
    }
}
int main()
{
    siv();
    res();
    int x;
    scanf("%d",&x);
    printf("%d\n",prime[x]);
    return 0;

}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<queue>
#include <sstream>
#include<string.h>
#include<math.h>
using namespace std;
int prime[1000005];
bool is_prime[1000005];
int seve(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(void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",seve(n));
    }
    return 0;
}