Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include <bitset> // compact STL for Sieve, better than vector<bool>!
#include <vector>
#include <cstdio>
#include <iostream>
#define ll long long 
#define vi vector<int>

using namespace std;

ll _sieve_size; 
bitset<10000010> bs; 
vi primes; 
void sieve(ll upperbound) { 
_sieve_size = upperbound + 1; 
bs.set(); 
bs[0] = bs[1] = 0; 
for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i);
} } 
bool isPrime(ll N) { 
if (N <= _sieve_size) return bs[N]; 
for (int i = 0; i < (int)primes.size(); i++)
if (N % primes[i] == 0) return false;
return true; 
} 

int tc,a;
int TestCase,x;

int main()
{
	sieve(1000100); 
	while(scanf("%d",&tc)!=EOF)
    {
        x=0;
        while(tc >= primes[x])
        {
            x++;
        }
        printf("%d\n",x);
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isprime (int n){

	if (n == 0 || n == 1){
		return false;
	}else if (n == 2){
		return true;
	}else if (n % 2 == 0){
		return false;
	} // end if
	
	for (int i = 3; i <= sqrt(n); i+= 2){
		if (n % i == 0){
			return false;
		} // end if
	} // end for
		
	return true;
}

int main()
{
	
//	cut here before submit 
//	freopen("testcase.prime", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	vector <int> prime(n+1, 0);

	int i;
	int count = 0;
	for (i = 2; i <= n; ++i){
		if (isprime(i)){
			++count;
		} // end if
		prime[i] = count;
	} // end for

	cout << prime[n] << endl; 

	return 0;
}

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

#define MAX 1000000

int main(){
	bool p[MAX+1];
	int num,answer;

	while ( scanf("%d" , &num) != EOF ){	
		p[0] = false;
		p[1] = false;
		for (int i=2 ; i<=MAX ; i++){
			p[i] = true;
		}
		answer = 0;

		for (int i=2 ; i<=sqrt(MAX)+1 ; i++){
			if (p[i]==1){
				for (int j=i*2; j<=MAX; j=j+i){
					p[j] = false;
				}
			}
		}

		for (int i=0; i<=num; i++){
			if (p[i]){
				answer++;
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}

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

int prime[1000010];
bool is_prime[1000010];
int n;
int main()
{
	while(cin>>n)
	{
		int p = 0;
		for(int i = 0;i <= n;i++)
		{
			is_prime[i] = true;    //先默认全不是素数 
		}
		is_prime[0] = is_prime[1] = false;
		for(int i = 2;i <= n;i++)
		{
			if(is_prime[i])
			{
				prime[p++] = i;
				for(int j = 2 * i;j <= n;j = j + i)
				{
					is_prime[j] = false;
				}
			}
		}
		cout<<p<<endl;
	}
}

C++: #include <iostream>
using namespace std;
??
#define Max 1000000
??
int prime [10000000];
??
int main()
{
????????int n, out;
??
????????for (int i = 2; i * i < Max; i++){
????????????????if (prime[i] == 0){
????????????????????????for (int j = i; j < Max; j += i){
????????????????????????????????if (!(j == i)) prime[j] = 1;
????????????????????????}
????????????????}
????????}
??
????????while (cin >> n){
????????????????out = 0;
????????????????for (int i = 0; i <= n; i++){
????????????????????????if (prime[i] == 0) out++;
????????????????}
????????????????cout << out - 2 << endl;
????????}
????????return(0);
}

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

bool IsPrime(int n){

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

	for(int i = 2; i < input; ++i){

		if(IsPrime(i)) ++count;
	}
	return count;
}
int main() {
	int input;

	cout << CheckNum(input) << endl;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x)
{
	if (x < 2)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	for (int i = 3; i <= (int)sqrt(x); i+=2)
		if (x%i == 0)
			return false;
	return true;
}
int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (cin.fail())
			break;
		int count = 0;
		for (int i = 1; i <= n; i++)
			if (isPrime(i))
				count++;
		cout << count << endl;
	}
}

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

using namespace std;

bool isprime(int n) {
	if (n < 2)
		return false;
	int lim = (int)sqrt((double)n);
	for (int i = 2; i <= lim; i++)
		if (!(n%i))
			return false;
	return true;
}

int main(void) {
	int n, total = 0;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		if (isprime(i))
			total++;
	}
	cout << total << endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

vector<int> makePrimes(int n) { 
    vector<int> res, pr(n + 1, 1);
    pr[0] = pr[1] = 0;
    for(int p=2;p<sqrt(n)+2;p++) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0;
    for(int p=2;p<n + 1;p++) if (pr[p]) res.push_back(p);
    return res;
}

int main(){
	int a;
	while(scanf("%d",&a)!=EOF){
		cout << makePrimes(a).size() << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

bool isPrime(int num);

int main()
{
	int count = 0;
	/*int m = 2, n = 0, num;

	cin >> num;

	int *data = new int[num + 1];
	int *result = new int[num + 1];

	data[0] = 0;
	data[1] = 0;

	do
	{
		for (i = 2 * m; i < num + 1; i += m)
		{

		}
	}
	while
	{

	}*/
	const int N = 9999999;
	int n;
	std::vector<bool> isPrime(N + 1, true);    // ?´???°????????°?????¨??¨ON???

	while (cin >> n)
	{
		count = 0;
		for (int i = 2; i < n; ++i) {
			if (isPrime[i])
			{
				count++;

				for (int k = i + i; k <= n; k += i)
					isPrime[k] = false;      // ?´???°????????°????´???°????????°?????¨???OFF???
			}
		}

		cout << count << endl;
	}
	
	return 0;






	
}

C++: #include<stdio.h>

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

int main(){
  int a;
  while(scanf("%d",&a)!=EOF){
    int i,ans=0;
    for(i=0;i<=a;i++){
      if(isPrime(i))ans++;
    }
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <iostream>

using namespace std;
int ns[1000000];
int main()
{
    int n;
    while(cin>>n)
    {
        fill(ns,ns+1000000,true);
        ns[1]=false;
        int cnt=0;
        for(int i=2;i<=n;++i){
            if(ns[i])cnt++;
            for(int j=0;j*i<=n;++j){
                ns[i*j]=false;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<'\n';}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;tag:m[i]=e;}}