Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[30];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num <30; data_num++)
	{
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0)
			break;
	}

	for (k = 0; k < data_num; k++)
	{

		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);
		prime[0] = 0;

		for (i = 1; i < data[k]; i++)
		{
			prime[1] = 1;
		}

		for (i = 1; i < sq_num; i++)
		{

			if (prime[i] == i)
			{
				for (j = (i + 1); (i + 1)* j <= data[k]; j++)
				{
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0; 
		for (i = 0; i < data[k]; i++)
		{
			if (prime[i] == 1)
			{
				cnt++;
			}
		}
		printf("%d\n", cnt);
		free(prime);
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int N;

int main() {
    vector<bool> is_prime(1000000,true);
    vector<int> prime(1000000,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i <= 1000000; ++i){
        if(is_prime[i]){
            ++p;
            for(int j = i*2; j <= 1000000; j += i) is_prime[j] = false;
        }
        prime[i] = p;
    }

    for(int i = 0; i <= 30; ++i){
        cin >> N;
        cout << prime[N] << '\n';
    }
    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>
using namespace std;

int main(){
	int n,w=0;
	cin >> n;
	for(int j=n;j>1;j--){
		for(int i=2;i<j;++i){
			if(j%i == 0){
				break;
			}
			if(i=j-1){
				w++;
			}
		}
	}
	cout << w;	
	return 0;
}

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

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

int main(){
	int Cheat[1000000],cnt = 0;
	Cheat[0]=0;Cheat[1]=0;
	for(int i = 0; i < 1000000; i++){
		if(isPrime(i)){
			cnt++;
		}
		Cheat[i] = cnt;
	}
	while(true){
		int n;
		cin >> n;
		if(cin.eof()){
			break;
		}
		cout << Cheat[n] << endl;
	}
	return 0;
}

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

C++: #include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

const int N = 100000;

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N+1)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

C++: #include <stdio.h>
int main(){
	int i,j,n,num;
	bool prime[1000000];
	bool flag=true;
	for(i=0;i<999999;i++) prime[i]=true;
	while(scanf("%d",&n)!=EOF){
		num=0;
		for(i=2;i<n+1;i++){
				for(j=i*2;j<n+1;j=j+i) prime[j]=false;
		}
		for(i=2;i<n+1;i++){
			if(prime[i]==true) num++;
		}
		printf("%d\n",num);
	}
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << n - primes.count() - 1 << " ";
  }
}

C++: #include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>L;X--)
#define DEP2(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
const int MAXN=1e7+5;


int phi[MAXN];
void eular(){
 	for(int i = 0; i<MAXN;i++) phi[i] = 1;
 	for(int i = 2; i<MAXN;i++)
 		if(phi[i] == 1)
 			for(int j = i+i;j<MAXN;j+=i)
 				phi[j] = 0;
 }
 
 
 int main(){
 	eular();
 	int n;
 	while(cin>>n)
 	{
 		int cnt=0;
 		REP2(i,2,n){
 			if(phi[i]) cnt++;
 		}	
 		cout<<cnt<<endl;
 		
	}
 	
 	
 	return 0;
 }

C++: #include<iostream>
using namespace std;
const int MAX_V = 1000000;
int prime[MAX_V+1];
int pcount[MAX_V];
int main() {
    int i, k,a,sum=0;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1; // 2??\????´???°??¨??????
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°2?????\????????°?´???°??§?????? 
            }
            
        } 
        
    }
    pcount[0]=0;
    pcount[1]=0;
    for(i=2;i<MAX_V;i++){
        if(prime[i]){
            sum++;
        }
        pcount[i]=sum;
    }
    for(i=0;i<30;i++){
        scanf("%d",&a);
        printf("%d\n",pcount[a]);
    } 

    return 0; 
    
}

C++: #include<stdio.h>
#include<memory.h>
#include<math.h>
int a[999999]={0};
int main()
{
	int n,max=0;
	while(~scanf("%d",&n))
	{
		if(max>n) 
		{
			printf("%d\n",a[n]); 
			continue;
		}
		
		int sum=0;
		for(int i=max;i<=n;i++)
		{
			int flag=0;
			for(int j=2;j<=sqrt(i*1.0);j++)
				if(i%j==0) 
				{
					flag=1;
					break;
				}
			if((flag==0)&&i!=0&&i!=1) sum++;
			a[i]=a[max]+sum;
		}
		max=n;
		printf("%d\n",a[n]);
	}
	return 0;
}

C++: #include <cstdio>
#define N 999999
unsigned char p[((N+1)/2+7)/8];
int main() {
	int i,j,s,n=3;
	for(i=0;n<=(N/2);i++,n+=2)
		if(!(p[i/8]&(1<<(i%8))))
			for(j=i+n;j<((N+1)/2);j+=n)p[j/8]|=(1<<(j%8));
	while(scanf("%d",&n)!=EOF) {
		if(n<2){printf("0\n");continue;}
		if(n==2){printf("1\n");continue;}
		for(i=3,j=0,s=1;i<=n;i+=2,j++)
			s+=!(p[j/8]&(1<<(j%8)));
		printf("%d\n",s);
	}
}