Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

class PrimeNumbers
{
public:
	vector<int> primeNumbers;

	PrimeNumbers()
	{
		this->createPrimeNumbers();
	}
	
	int answer(int N)
	{
		int result = 0;
		for(auto it = this->primeNumbers.begin(); it != this->primeNumbers.end(); it++)
		{
			if(*it <= N)result++;
			else break;
		}
		return result;
	}

	bool checkOf(int n)
	{
		if(n % 2 == 0)return false;

		bool prime = false;
		for(auto it = this->primeNumbers.begin(); it != this->primeNumbers.end(); it++)
		{
			if(n == *it)
			{
				prime = true;
				break;
			}
		}
		return prime;
	}

	void createPrimeNumbers()
	{
		int max_number = 999999+1;
		this->primeNumbers = vector<int>();
		this->primeNumbers.push_back( 2 );
		for(int i = 3; i < max_number; i += 2)
		{
			bool prime = true;
			for(auto it = this->primeNumbers.begin(); it != this->primeNumbers.end(); it++)
			{
				if(i % *it == 0)
				{
					prime = false;
					break;
				}
			}
			if(prime)
			{
				this->primeNumbers.push_back(i);
			}
		}
	}

};

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

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

int main(){
int unti[100001] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100000;n++){
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100000;a++)
{unti[a * n]++;}}}
int b;
while(cin >> b ){
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}
return 0;
}

C++: #include<iostream>
using namespace std;
 
__forceinline int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

	for(int i=3; i*i<=n; i+=2){
		if(n%i==0){
			return 0;
		}
	}
	return 1;

}

//0009
int main()
{
	int n;
 
	while(cin >> n){
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<fstream>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<ctime>
#include<climits>
#include<ctype.h>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
#define PI acos(-1.0)
#define eps 1e-12
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ll N = 1e6+1;
const int MOD = 1e9+7;
bool flag = true;
int prime[N];
bool check[N]{0};
int main()
{
	//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
	//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
	//%%%llaa
    int i,j,n,tot=0;
    for(i=2;i<N;i++)
    {
        if(!check[i])
        {
            prime[tot++]=i;
            for(j=i+i;j<N;j+=i)
                check[j]=1;
        }
    }
    int p=30;
    while(~scanf("%d",&n)&&p)
    {
        p--;
        int num=0;
        i=0;
        while(prime[i++]<=n)
            num++;
        printf("%d\n",num);
    }
	return 0;
}


/*

*/

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}


int main(){
int n;
while (cin>>n){
	int yakusu=0;
	for (int i=2;i<=n;i++){
		bool flag=true;
		for (int j=2;j<i-1;j++){
			if(i%j==0){
				flag=false;
			}
		}
		if (flag){
		yakusu++;
		}

	}
cout<<yakusu<<endl;
}
	}

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

typedef long long LL;
using namespace std;

const int X = 10000001;
bool isPrime[X];

void init(){
  for(int i=0;i<X;i++){
    isPrime[i] = false;
  }
  isPrime[2] = true;
  for(int i=3;i<X;i+=2){
    cout << i << endl;
    bool ok = true;
    for(int j=2;j<=sqrt(i);j++){
      if(!isPrime[j])continue;
      if(i%j==0)ok=false;
    }
    if(ok)isPrime[i] = true;
  }
}

int main(){
  init();
  int n;
  while(cin >> n){
    int answer = 0;
    for(int i=0;i<n+1;i++){
      if(isPrime[i])answer++;
    }
    cout << answer << endl;
  }
  return 0;
}

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

int main() {
	vector<int> primes;
	primes.push_back(2);
	primes.push_back(3);
	for (int n = 4; n != 1000; ++n) {
		bool isPrime = true;
		for (int i = 0; i != primes.size(); ++i) {
			if (n % primes[i] == 0) {
				isPrime = false;
			}
		}
		if (isPrime) {
			primes.push_back(n);
		}
	}

	int n;
	while (cin >> n) {
		int count = 0;
		for (int i = 0; i != primes.size(); ++i) {
			if (primes[i] <= n)
				++count;
			else 
				break;
		}
		cout << count << endl;
	}

	return 0;
}

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

int main()
{
	int counter=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<'0'<<endl;
			break;
		}

		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				counter++;
			flag=1;
		}
		cout<<counter<<endl;
		counter=0;
	}
}

C++: #include <iostream>

int prime_numbers[999999];
int cur_index = 4;

bool is_prime(int p) 
{
    for (int i = 0; i < cur_index; i++) {
        if (p % prime_numbers[i] == 0) {
            return false;
        }
    }
    return true;
}

int main(void)
{
    prime_numbers[0] = 2;
    prime_numbers[1] = 3;
    prime_numbers[2] = 5;
    prime_numbers[3] = 7;

    long long int n;
    std::cin >> n;

    for (int i = 8; i <= n; i++) {
        if (is_prime(i)) {
            prime_numbers[cur_index] = i;
            cur_index++;
        }
    }

    std::cout << cur_index << std::endl;
    return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool prime(int num){
	if(num<2)return false;
	else if(num==2)return true;
	else if(num%2==0)return false;
	double sqrtNum = sqrt((double)num);
	for(int i=3;i<=sqrtNum;i++){
		if(num%i==0)return false;
	}
	num=0;
	return true;
}
int main(){
	int n,count=0;
	while(cin>>n){
		for(int ii=1;ii<=n;ii++){
		count+=prime(ii);
		}
		cout<<count<<endl;
		count=0;
	}
	return 0;
}