Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 100000
int p[MAX+1];
void f(){
	int n=0;
	for(int i=2;i<=MAX;i++){
		if(p[i]==0){
			p[i] = ++n;
			for(int j=2;j*i<=MAX;j++)
				p[j*i] = -1;
		}
		else p[i] = n;
	}
} 
int main(){
	int n;
	f();
	while(cin>>n){	
		cout<<p[n]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main()
{
	bool *sosu;
	int *ans,now,n;

	sosu = new bool[1000000];
	ans = new int[1000000];

	for(int i = 0; i < 1000000; i++){
		sosu[i] = true;
	}
	sosu[0] = sosu[1] = false;
	for(int i = 0; i < 1000000; i++){
		if(sosu[i] == true){
			for(int j = 2; j*i < 1000000; j++){
				sosu[j*i] = false;
			}
		}
	}
	now = 0;
	for(int i = 0; i < 1000000; i++){
		if(sosu[i] == true)
			now++;
		ans[i] = now;
	}

	while(scanf("%d",&n) != EOF){
		printf("%d\n",ans[n]);
	}

	return 0;
}