Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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

const int MAX_VALUE = 1000000;

class PrimeNumbers
{
public:
	vector<bool> primeNumbers;

	PrimeNumbers()
	{
		this->createPrimeNumbers();
	}
	
	int answer(int N)
	{
		int result = 0;
		for (int i = 0; i <= N; i++)
		{
			if (this->primeNumbers[i])
			{
				result++;
			}
		}
		return result;
	}

	void createPrimeNumbers()
	{
		
		this->primeNumbers = vector<bool>(MAX_VALUE, true);
		this->primeNumbers[0] = false;
		this->primeNumbers[1] = false;
		for (long long i = 2; i < MAX_VALUE; i++)
		{
			for (long long j = i * i; j < MAX_VALUE; j += i)
			{
				this->primeNumbers[j] = false;
			}
			
		}
	}

};

int main()
{
	int N;
	PrimeNumbers pn = PrimeNumbers();
	
	while(cin >> N)
	{
		cout << pn.answer(N) << endl;
	}
	return 0;
}

C++: #include <stdio.h>
 
int main(){
    int e[30];
 
    int k = 0;
    while( scanf( "%d",&e[k] ) != EOF )k++;
 
    for( int i = 0;i < k;i++ ){
        int n = 1;
        int k = 0;
        while( true ){
            if( e[k] => n ){
                k++;
                n *= 10;
            } else {
                break;
            }
        }
        printf( "%d\n",k );
    }
    return 0;
}

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

using namespace std;
static const int MAXV = 1000000;

int sosuu_list[MAXV];

void make_sosuu_list() {
  for(int i=0;i<MAXV;i++) sosuu_list[i] = 1;
  sosuu_list[0] = sosuu_list[1] = 0;
  for(int i=2;i<MAXV;i++) {
    if(sosuu_list[i]) {
      for(int j=i+i;j<MAXV;j+=i) sosuu_list[j] = 0;
    }
  }
  for(int i=1;i<MAXV;i++)sosuu_list[i]+=sosuu_list[i-1];
}

int main() {
  int n;
  make_sosuu_list();
  while(/*scanf("%d", &n) == 0) {*/!feof(stdin)) {
    scanf("%d", &n);
    if(feof(stdin)) break;
    printf("%d\n", sosuu_list[n]);
  }
}

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

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=1000100;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

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

int main()
{
	int n,c;

	while(cin >> n){
		c = 0;
		bool flag = false;

		for(int i=2;i<n+1;++i){
			for(int j=2;j<i;++j){
				if(i%j == 0)
					flag = true;
			}

			if(!flag)
				++c;
			flag = false;

		}

		cout << c << endl;

	}
	return 0;
}

C++: #include <iostream>

bool Check(int);

int main(void)
{
    int input;
    int count;
    for(int i=0;i < 30;++i){
        std::cin >> input;
        count = 0;
        for(int j=2;j <= input;++j){
            if(Check(j)){
                ++count;
            }
        }
        std::cout << count << std::endl;
    }
    return 0;
}
bool Check(int value)
{
    bool result = true;
    for(int i=value / 2;i >= 2;--i){
        if(value % i == 0){
            result = false;
            break;
        }
    }
    return result;
}

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

int main() {
	int n;
	while(cin >> n && n != EOF) {
		bool* prime = new bool[n+1];
		int count = 0;
		for(int i = 0; i <= n; ++i) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
				cout << i << '\t';
				for(int j = 2 * i; j <= n; j += i) {
					prime[j] = false;
				}
			}
		}
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
				count++;
			}
		}
		
		cout << count << endl;
		delete[] prime;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[80000];
    int n;
    a[0]=2;
    int k=1;
while(cin>>n){
    for(int i=3;i<=n;i+=2){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<k<<endl;
    k=1;
 }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+1000;
const int maxn=1000000+5;
int prime[maxn];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt]=i;
       	cnt++;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	/*for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";*/
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}

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

class PrimeBox
{
private:
	bitset<1000000> m_box;
	size_t m_size;

public:
	PrimeBox() :
		m_box(),
		m_size(2)
	{
		m_box.set();
		m_box.reset(0);
		m_box.reset(1);
	}

private:
	void expand(size_t size)
	{
		for(size_t i = m_size + 1; i <= size; i++)
		{
			for(size_t j = 2; j < i; j++)
			{
				if(!m_box.test(j))
					continue;

				if(i % j == 0)
				{
					m_box.reset(i);
					break;
				}
			}
		}
		m_size = size;
	}

public:
	bool isPrime(size_t number)
	{
		if(m_size < number)
			expand(number);

		return m_box.test(number);
	}
};

int main()
{
	PrimeBox box;

	size_t n;
	while(cin >> n)
	{
		int found = 0;
		for(size_t i = 2; i <= n; i++)
		{
			if(box.isPrime(i))
				found++;
		}

		cout << found << endl;
	}

	return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;
  int num;
  int i,flag,count;

  while(scanf("%d",&n)!=EOF) {

    count=0;

    for(num=1;num<=n;num++) {

      flag=1;

      for(i=2;i<num/2+1;i++) {
	if(num%i==0) {
	  flag=0;
	  break;
	}
      }
      
      if(num==1) flag=0;

      if(flag==1) {
	printf("%d\n",num);
	count++;
      }
    }

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

  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

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

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; RE;}
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)) ans++;
    }
    cout<<ans<<en;
  }
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n,c;
	while(scanf("%d",&n)!=EOF){
		c=1;
		for(int i=3;i<=n;i+=2){
			if(isprime(i))c++;

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