Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: #include<iostream>

using namespace std;



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

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

using namespace std;

int main()
{
	int n,ans,flag;

	while(scanf("%d",&n)!=EOF){
		ans=0; 
		for(int i=2;i<=n;i++){
			flag=1;
			for(int j=2;j*j<=i;j++){
				if(i%j==0) {flag=0;break;}
			}
			if(flag) ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}

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

int main(){
  int a,j,cou;
  while(cin>>a){
    cou=0;
    for(int i=2;i<=a;i++){
      if(i==2){
	cou++;
	continue;
      }
      else if(i%2==0)continue;
      for(j=3;j*j<=i;j+=2)if(i%j==0)break;
      if(j*j>i)cou++;
    }
    cout <<cou<<endl;
  }
  return 0;
}

C++: #include <iostream>

bool divisible( int u, int v )
{
    return (u % v) == 0 ? true : false;
}

int num_divisors( unsigned int start, unsigned int end )
{
    if ( start == end ) return 1;
    return divisible( end, start ) + num_divisors( start+1, end );
}

int no_of_divisor( unsigned int n )
{
    return num_divisors( 1, n );
}

bool is_prime( unsigned int n )
{
    return (no_of_divisor(n) == 2);
}

int count_prime( unsigned int n )
{
    int count = 0;
    for ( unsigned int i = 1; i <= n; ++i )
    {
        if ( is_prime(i) ) ++count;
    }
    return count;
}

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

C++: #include<bits/stdc++.h>
using namespace std;

#define maxPN 100000
#define PNs  1000100
int countPN = 0, countPNs = 0;
int PrimeNum[maxPN], temp;
bool PN[PNs];

bool IsPrimeNumber(int x);

void PrimeN(){
	int i, j;
	PrimeNum[0] = 2;
	PN[2] = true;PrimeNum[countPN++] = 2;
	PN[3] = true;PrimeNum[countPN++] = 3;
//	PN[5] = true;PrimeNum[countPN++] = 5;
	
	for(i = 6; i  < PNs;i+=6){
		if(IsPrimeNumber(i-1)){
			PrimeNum[countPN++] = i-1;
			PN[i-1] = true;//cout<<i-1<<endl;
		}
		if(IsPrimeNumber(i+1)){
			PrimeNum[countPN++] = i+1;
			PN[i+1] = true;//cout<<i+1<<endl;
		}
		countPNs = i+1;//cout<<i-1<<" "<<PN[i-1]<<endl;
	}
}

bool IsPrimeNumber(int x){
	//if(x == 2 || x == 3) return true;
	//if(x <= 4 || x%2 == 0 || x%3 == 0)   return false;
	//if(x < countPNs) return PN[x];
	for(int i = 0; PrimeNum[i] * PrimeNum[i] <= x; i++)
		if(x%PrimeNum[i] == 0)return false;
	return true;
}


int main(){
//	clock_t start, end;
	int n = true, counta;
//	start = clock();
	PrimeN();
	cout<<PrimeNum[countPN-1]<<" "<<countPNs<<endl;
//	cout<<clock()-start<<"ms"<<endl;
	
	while(cin>>n){
		counta = 1;
		
		
		//cout<<(IsPrimeNumber(n)?"yes":"no")<<endl;
	//	start = clock();
		//cout<<IsPrimeNumber(n)<<endl;
		for(int i = 1; i <= n; i+=2){
			if(PN[i])counta++;
		//	cout<<i<<" "<<PN[i]<<endl;
		}
		if(n == 1) counta = 0;
		cout<<counta<<endl;
	//	cout<<clock()-start<<"ms"<<endl;
	}
	return 0;
}

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

bool check(int in){
	for (int i = 3; i<=sqrt(in); i+=2){
		if (in % i == 0)
			return false;
	}
	return true;
}

int PrimeNumber(int in){
	int count = 0;
	if (in > 2)	count++;
	for (int i = 3; i <=in; i+=2){
		if (check(i))	count++;
	}

	return count;
}

int main(){
	int in;
	while (cin >> in, !cin.eof()){
		cout << PrimeNumber(in) << endl;
	}
}

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;
        if(i%2==0&&i!=2)
            k=1;
      for(j=3;j*j<=i&&k==0;j+=2)
      {
          if(i%j==0)
          {
              k=1;
              break;
          }
      }
       if(k==0)
          {
             ++s;
          }
    }
        printf("%lld\n",s);
    }
}

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

int main(void)
{
	int num, cnt;
	unsigned int i, j;
	int data_num;
	unsigned int sq_num;
	unsigned int *prime;

	scanf("%d", &num);

	sq_num = (int)sqrt((double)num);
	prime = (unsigned int*)malloc(sizeof(unsigned int) * num);

	for (i = 0; i < num; i++) {
		prime[i] = 1;
	}

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

	cnt = 0;
	for (i = 0; i < num; i++) {
		if (prime[i] == 1) {
			cnt++;
			//printf("%d", i + 1);
		}
	}

	printf("%d\n", cnt);

	free(prime);

	return 0;

}

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

int main(){
 bool is_prime[1000000]; //?´???°???????????¨

 is_prime[0] = is_prime[1] = false;

 for(int i=2; i<1000000; i++){
  is_prime[i] = true;
 }

 for(int i=2; i*i<1000000; i++){
  if(is_prime[i]){
   for(int j=i*i; j<1000000; j+=i){
    is_prime[j] = false;
   }
  }
 }

 int n_prime[1000000]; //?´???°????????°?????¨

 int cnt = 0;

 for(int i=0; i<1000000; i++){
  if(is_prime[i]){
   cnt++;
  }
  n_prime[i] = cnt;
 }

 while(true){
  int n;
  cin >> n;

 if(cin.eof()) break;

 cout << n_prime[n] << endl;
 }

 return 0;
}

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



int main(){
	int i , j , n , pn;
	
	while(cin>>n){
		pn=1;
		for(i=3 ; i<=n ; i++){
			for (j=2 ; j<i ; j++){
				if (i%j==0) goto skip;
			}
			pn++;
			skip:;
		}
		if(n==0 || n==1 ) {
			cout << 0 << endl;
		} else {
			cout << pn << endl;
		}
	}
	return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;

int f[1000001];
int main(){
    fill_n(f,1000001,1);
    f[0]=f[1]=0;
    
    for(int i=2;i<1000001;i++){
        f[i]+=f[i-1];
        if(!f[i])continue;
        for(int j=i+i;j<1000001;j+=i)f[j]=0;
    }
    
    int N;
    
    while(scanf("%d",&N)!=EOF){
        printf("%d\n",f[N]);
    }
    
    return 0;
    
}

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

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        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;
}