Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> v;
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i * i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int data,i,j,k=0,l=0,kai[1000]={0},s[1000000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<=1)
		   kai[k]=0;
		else
		{
			for(i=2;i<=data;i++)s[i]=i;

		    i=2;
			while(i*2<data)
			{
			  if(s[i] != 0)
			  {  
				 j=2;
				while(j*i<=data)
				{
					s[j*i]=0;
					j+=1;
				}
			  }
			  i+=1;
			}

			
			for(i=2;i<=data;i++)
			{	
				if(s[i]!=0)
				{
					kai[k]+=1;
				}
			}
		}
		k+=1;
	}

  for(i=0;i<k;i++)
	  printf("%d",kai[i]);

  return 0;
}

C++: #include <cstdio>
#define N 999999
unsigned char p[((N+1)/2+7)/8];
int main() {
    int i,j,s,n=3;
    for(i=0;n*n<=N;i++,n+=2)
        if(!(p[i/8]&(1<<(i%8))))
            for(j=i+n;j<((N+1)/2);j+=n)p[j/8]|=(1<<(j%8));
    while(scanf("%d",&n)!=EOF) {
        if(n<2){printf("0\n");continue;}
        if(n==2){printf("1\n");continue;}
        for(i=3,j=0,s=1;i<=n;i+=2,j++)
            s+=!(p[j/8]&(1<<(j%8)));
        printf("%d\n",s);
    }
}