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 <set>
using namespace std;
int main() {
  long n;
  set<long> primes;
  primes.insert(2);
  while (cin >> n) {
    for (int i = 3; i <= n; i++) {
      bool prime = true;
      for (long j : primes)
        if (i % j == 0) {
          prime = false;
          break;
        }
      if (prime) primes.insert(i);
    }
    int x = 0;
    for (long j : primes)
      if (j <= n) x++;
    cout << x << endl;
  }
}

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

int n;
int known_primes[500000];
int pointer = 0;

void dump_known_primes()
{
	for (int i = 0; i < pointer; i++) {
		std::cout << known_primes[i] << ' ';
	}
	std::cout << std::endl;
}

bool get_input()
{
//	std::cout << "get_input\n";
	return (std::cin >> n);
}

// a < known_primes[pointer+1] ÌÍÍÅ
// a ªf©Ç¤©»è·é
bool is_prime(int a)
{
//	std::cout << "is_prime\n";
	for (int i = 0; known_primes[i] <= std::sqrt(a); i++) {
		if (a % known_primes[i] == 0) {
			return false;
		}
	}
	return true;
}

// mçêÄ¢È¢ÌfðT·
void search_next_prime()
{
//	std::cout << "searcn_next_prime\n";
	int a;
	for (a = known_primes[pointer] + 2; !is_prime(a); a += 2);
	pointer++;
	known_primes[pointer] = a;
}

// XXX
int solve(int a)
{
//	std::cout << "solve\n";
	if (a <= known_primes[pointer]) {
//		std::cout << "a: " << a << ' ' << "pointer: " << pointer << std::endl;
		int i = pointer;
		while (a < known_primes[i]) {
//			std::cout << "i: " << i << std::endl;
			i--;
		}
		return i+1;
	} else {
		search_next_prime();
		return solve(a);
	}
}

int main()
{
//	std::cout << "main\n";
	known_primes[0] = 2;
	known_primes[1] = 3;
	known_primes[2] = 5;
	pointer = 2;
	while (get_input()) {
		std::cout << solve(n) << std::endl;
//		dump_known_primes();
	}
	return 0;
}

C++: #include<iostream>

int main(){

	bool data[100001];

	for (int i = 0; i < 100001; i++)
		if (i % 2 == 0)
			data[i] = false;
		else
			data[i] = true;

	int in;

	int res=0;

	for(int i=2;i<=100000;i++){
		if (i % 2 != 0) {
			for (int j = 2; j < i; j++) {
				if (i%j == 0) {
					data[i] = false;
					goto fl;
				}
			}
		}
	fl:;
	}

	while (true) {

		std::cin >> in;

		for (int i = 2; i <= in; i++) {
			if (data[i] == true)
				res++;
		}

		std::cout << res << std::endl;

	}

		return 0;
}

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

int getPrimeCount(int n) {
    vector<bool> isPrime(n+1, true);
    int count = 0;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            count++;
            for (int j = i*2; j <= n; j+=i) {
                isPrime[j] = false;
            }
        }
    }
    return count;
}

int main() {
    int n;
    while (cin >> n) {
        cout << getPrimeCount(n) << endl;
    }
}

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

const bool isPrime(const int p)
{
    if(p == 2)
    {
        return true;
    }

    if(p < 2 || p % 2 == 0)
    {
        return false;
    }

    for(int i = 3; i <= sqrt(p); i += 2)
    {
        if(p % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main(void)
{
    bool p[1000000];

    for(int i = 0; i < 1000000; ++i)
    {
        p[i] = isPrime(i);
    }

    int n;

    while(std::cin >> n)
    {
        int result = 0;

        for(int i = 0; i <= n; ++i)
        {
            result += p[i];
        }

        std::cout << result << std::endl;
    }

    return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		cnt = 0;
		fg = 0;
		for (i = 3; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		//printf("cnt=%d\n", cnt);
		if (n >= 2)
			cnt++;
		cout << cnt << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>
int main(){
 int n,cnt=0;
 scanf("%d",&n);
 int a[n+1];
 memset(a,-1,sizeof(int)*(n+1));
 for(int i=2;i<=n;i++){
 if(a[i]==-1){ con++;
 for(int j=i;j<=n;j=j+i) a[j]=0;}
}
return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define un unsigned
#define de double
#define pi acos(-1.0)
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
#define mem(ae, value) memset(ae, value, sizeof(ae))
#define all(x) x.begin( ), x.end( )
#define UNIQUE(x) x.resize(unique(all(x)) - x.begin())
#define FASTER ios_base::sync_with_stdio(0)
#define loop(begin, end) for(u int i=begin; i<=end; i++)
#define Read freopen("in.txt", "r", stdin)
#define Write freopen("out.txt", "w", stdout)
#define nl '\n'

using namespace std;

template<class T> inline T sq(T x) { return x*x; }
template <class T> inline T gcd(T a, T b) { if(b == 0) return a; return GCD(b, a%b); }
template <class T> inline T lcm(T a, T b) { return ( a/GCD(a, b) ) * b; }
template <class T> inline T power(T b, T p)
{
    if(p == 0) return 1;
    if(p == 1) return b;
    if(p&1) return b*power(b, p-1);
    else return sq(power(b, p>>1));
}

bool P[500000+10];

void sieve(int n)
{
    for(int i=3; i*i<=n; i+=2)
    {
        if( (P[i/2-1]) == 0 )
        {
            for(int j=i*i; j<=n; j+=2*i)
            {
                P[j/2-1] = 1;
            }
        }
    }
}

void display()
{
    for(int i=0; i<60; i++)
    {
        cout << i << " = " << (i*2+3) << " --- " << P[i] << nl;
    }
}


int main( )
{
    sieve(500000);
    int n;
    while(cin >> n)
    {
        int C=0;
        if( (n==1) or (n==2))
        {
            if(n==1) C=0;
            else
            {
                if(n==2) C=1;
            }
        }
        else
        {
            int upto;
            if((n&1))
            {
                upto = n/2 - 1;
            }
            else
            {
                upto = n/2 - 2;
            }
            int i=0;
            while(i<=upto)
            {
                if(P[i]==0) C ++;
                i ++;
            }
            C ++;
        }
        cout << C << nl;
    }
    //display( );

    return 0;
}

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

int main()
{
	int n=0;
	int a[40]={0};
	while(cin>>a[n++]);n--;
	
	int maxn=1000000;
	bool p[maxn];
	for(int i=0;i<maxn;i++)
	{
		p[i]=1;
	}
	for(int i=2;i<maxn;i++)
	{
		for(int j=i+i;j<maxn;j+=i)
		{
			p[j]=0;
		}
	}
	
	for(int i=0,cnt=0;i<n;i++)
	{
		for(int j=2;j<=a[i];j++)
		{
			cnt+=p[j];
		}
		cout<<cnt<<endl;cnt=0;
	}
	return 0;
}

C++: #include <stdio.h>
#include <math.h>
using namespace std;


int main() {

//変数の宣言

	int i,n,j,sum,judge=1;
	
	while(scanf("%d",&n)){
		sum = 1;
		for(i=3;i<n+1;i+=2){
			for(j=3;j<=sqrt(i);j+=2){
				if(i%j==0){
					judge = 0;
					break;
				}
			}
			if (judge==1){
				sum++;
			}
			judge = 1;
		}
		
		printf("%d\n",sum);
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,count,sc;
  while(cin>>n){
    count = 0;
    for(int i=2;i<=n;i++){
      sc = 0;
      for(int j=2;j<=i;j++) if(i%j==0) sc++;
      if(sc==1) count++;
    }
    cout << count << endl;
  }
  return 0;
}