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 <cmath>
using namespace std;

bool IsPrime(int i){
    if(i < 2) return false;
    else if(i == 2) return true;
    else if(i % 2 == 0) return false;

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

    return true;
}

int main(){
    int n;
    while(cin >> n){
        int k = 0;
        for(int i = 0; i <= n; ++i){
           if(IsPrime(i) == true){
               k++;
           }else ;
        }
        cout << k << endl;
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool isprime(int& num)
{
    static int c;
    for(c=2; c < sqrt(num)+1; c++)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans = 0;
    int buff;
    while(cin >> buff);
    {
        for(int d =2; d <= buff; d++)
            if(isprime(d)) ans++;
        cout << ans << " ";
        ans  = 0;
    }
    cout << endl;
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int num,i,cnt;


	while(cin >> num){
		cnt=1;
		for(i=3;i <= num;i+=2){
			bool swa = true;
			for(int j=3; j*j <= i;j+=2){
				if(i % j == 0){
					swa=false;
					continue;
				}

			}
			if( swa == true ){
				cnt++;
//				cout << i << " ";
			}
		}
		cout << cnt <<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool prime[1000000];
		for(int l=2;l<=n;l++){
			prime[l] =true;
		}
		for(int i=2;i<=n;i++){
			if(prime[i]==true){
				for(int j=i*2;j<=n;j+=i){
					prime[j]=false;
				}
			}
		}
		int count=0;
		for(int k=2;k<=n;k++){
			if(prime[k]==true) count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int s[80000],m[1000000],i,j,n=0;
int main() {
	for (i=2; i<1000000 ; i++) {
		if (m[i]==0) {
			s[n++]=i;
			for (j=i; j<1000000; j+=i) m[j]=1;
		}
	}
	while(cin >> i) {
		for (j=0;s[j]<=i && j<n;j++) ;
		cout << j << endl;
	}
return 0;
}

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

#pragma warning(disable:4996)

int main()
{
	int DataSet,nCnt,nCnt2,In,Total,Count;

	Total = 0;
	DataSet = 0;


	for (DataSet = 0; DataSet <= 30; DataSet++)
	{
		scanf("%d", &In);
		Total = 0;
		for (nCnt = 2; nCnt <= In; nCnt++)
		{
			Count = 0;
			for (nCnt2 = nCnt; nCnt2 >= 2; nCnt2--)
			{
				if (nCnt%nCnt2 == 0)
				{
					if (nCnt != nCnt2)
					{
						Count++;
						break;
					}
				}
			}
			if (Count == 0)
				Total++;
		}
		printf("%d\n", Total);
	}

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    const int max_index = 1000000;
    int prime[max_index];

    prime[0] = 0;
    for (int i = 1; i < max_index; i++) 
        prime[i] = 1;

    for (int i = 1; i < (int)sqrt(max_index); i++) {
        if (prime[i] == 1)
            for (int j = i + 1; (i + 1) * j <= max_index; j++)
                prime[(i + 1) * j - 1] = 0;
    }

    int tmp = 0;
    for (int i = 0; i < max_index; i++) 
        (prime[i] == 0) ? (prime[i] = tmp) : prime[i] = ++tmp;
    prime[0] = 0;

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

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

using namespace std;

int main()
{ 
	int n;
	while (cin >> n)
	{
		vector<bool> a(n + 1, true);
		int cnt = n == 0 ? 0 : n - 1;

		// Sieve of Eratosthenes
		for (int i = 2; i*i <= n; ++i)
			if (a[i])
				for (int j = 0; i * (j + 2) <= n; ++j)
					if (a[i * (j + 2)]) a[i * (j + 2)] = false, cnt--;

		cout << cnt << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };


int main(){
	ios::sync_with_stdio(false);

	int n;
	int count;
	int nmax = 1000000;
	vector<bool> flag(nmax+1, true);

	flag[0] = !flag[0];
	flag[1] = !flag[1];

	for (int i = 2; i <= sqrt(nmax) + 1; i++){
		if (flag[i]){
			for (int j = i * 2; j <= nmax; j += i){
				flag[j] = false;
			}
		}
	}
	
	while (cin >> n){
		count = 0;
		for (int i = 0; i <= n; i++){
			if (flag[i])
				count++;
		}

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

}

C++: /*
	大号水?，拿来?手
*/
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int Find_Number (int x)
{
	int cnt = 0;
	for (int i=2;i<=x;i++)
	{
		bool flag = false;
		for (int j=2;j<=sqrt((double)i);j++)
		{
			if ( i % j == 0)
			{
				flag = true;
				break;
			}
		}
		if (flag == false )
		{
			cnt++;
		}
	}
	return cnt;
}

int main ()
{
	int N;
	while (scanf("%d",&N)!=EOF)
	{
		cout<<Find_Number (N)<<endl;
	}
	return 0;
}

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

bool isprime(int number, std::vector<int> const& primeset)
{
	int maxprime = static_cast<int>(std::sqrt(static_cast<float>(number)));

	typedef std::vector<int>::const_iterator Iter;
	Iter primesetlimit = std::upper_bound(primeset.begin(), primeset.end(), maxprime);
	for (Iter p = primeset.begin(); p != primesetlimit; ++p) {
		if (number % *p == 0) {
			return false;
		}
	}
	return true;
}

int resolve(int number)
{
	if (number < 2) {
		return 0;
	}
	if (number == 2) {
		return 1;
	}
	std::vector<int> primesetExceptTwo;
	for (int i = 3; i <= number; i += 2) {
		if (isprime(i, primesetExceptTwo)) {
			primesetExceptTwo.push_back(i);
		}
	}
	if (isprime(number, primesetExceptTwo)) {
		primesetExceptTwo.push_back(number);
	}
	return static_cast<int>(primesetExceptTwo.size()) + 1;
}

int main()
{
	int input;
	while (std::cin >> input) {
		std::cout << resolve(input) << std::endl;
	}

	return 0;
}