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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

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

bool isprime(int x) {
	if (x == 2)
		return true;
	if ((x < 2) || (x % 2 == 0)) {
		return false;
	}
	int i = 3;
	while (i == sqrt(x)) {
		if (x%i == 0)
			return false;
		i = i + 2;
	}
	return true;
}

int main()
{
	
	int n;
	while (cin >> n) {
		int C = 0;
		for (int i = 0; i <= n; i++) {
			if (isprime(i) == true)
				C++;
		}
		cout << C<<endl;
	}
	return 0;
}

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

int sieveOfEratosthenes(int n) {
    vector<int> prime;
    vector<int> isPrime((unsigned long)n + 1, true);
    isPrime[0] = false, isPrime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            prime.push_back(i);
            for (int j = 2 * i; j <= n; j+= i)
                isPrime[j] = false;
        }
    }
    return (int)prime.size();
}

int main() {
    int n;
    while (cin >> n) {
        cout << sieveOfEratosthenes(n) << endl;
    }
    return 0;
}

C++: #include <cstdio>
int d[1000000],c[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i]){c[i]=r;continue;}
		c[i]=++r;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int *p=upper_bound(prime,prime+num,n);
        int ans=p-prime;
        cout<<ans<<endl;
    }
    return 0;
}

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

int prime(int number) {
    int s_num = sqrt(number);
    if (number == 2) {
        return 1; 
    } else if (number % 2 == 0) {
        return 0;
    }
    for (int i = 3; i <= s_num; i += 2) {
        if (number % i == 0) {
            return 0;
        }
    }
    return 1;
}

int main(void) {
    int number;
    int count;

    while (std::cin >> number) {
        count = 0;
        for (int i = 2; i <= number; i++) {
            if (prime(i) == 1) {
                count++;
            }
        }
        std::cout << count << std::endl;

    }
    return 0;
}

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

#define rep(i, n) for(int i = 2; i <= n; i ++)

using namespace std;

int main(void){
	for(int n, count = 0; cin >> n; cout << count << endl, count = 0){
		vector<bool> numberList(n + 1);

		rep(i, n) numberList[i] = true;

		for(int i = 2; i * i <= n; i ++) for(int j = i; i * j <= n; j ++) numberList[i * j] = !(numberList[i * j]);
		
		rep(i, n) if(numberList[i]) count ++;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for (int a = 3; a<1000000; a++)
	{
		prime[a] = 1;
	}

	for (int a = 3; a<1001; a++)
	{
		if (checked[a] == 0)
		{
			checked[a] = 1;
			for (int b = 2; b<a; b++)
			{
				if (a%b == 0)
				{
					prime[a] = 0;
					break;
				}
			}
			if (prime[a] == 1)
			{
				for (int c = 2 * a; c<1000000; c += a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for (int a = 3; a<100; a++)
	{
		primesum[a] = primesum[a - 1] + prime[a];
		cout << "prime[" << a << "] = " << prime[a] << endl;
		cout << "primesum[" << a << "] = " << primesum[a] << endl;
	}

	while (cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;

int sosuu(int n);

int main(){
    int n=0;
    int num=0;
    int a[30][2]={0};
    int max=0;
    while(scanf("%d",&n)!=EOF){
        if(max<n){
            max=n;
        }
        a[num][0]=n;
        num++;
    }
    
    int b[max];
    int c[max];
    int so=0;
    for(int i=0; i<=max; i++){
        b[i]=i;
    }
    b[1]=0;
    
    for(int i=2; i<sqrt(max); i++){
        if(b[i]!=0){
            for(int j=i+1; j<=max; j++){
                if(j%i==0){
                    b[j]=0;
                }
        }
        }
    }
    
    for(int i=0; i<=max; i++){
        if(b[i]!=0){
            c[so]=i;
            so++;
        }
    }
    
    
//    for(int j=0; j<num; j++){
//        cout<<a[j][0]<<"\n";
//    }
//    
//    for(int j=0; j<=so; j++){
//        cout<<c[j]<<"\n";
//    }
    
    
    
    
    for(int i=0; i<num; i++){
        for(int j=0; j<so; j++){
            if(c[j]<=a[i][0]){
                a[i][1]++;
            }else{
                j=so;
            }
        }
    }

    
    for(int j=0; j<num; j++){
        cout<<a[j][1]<<"\n";
    }
    
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;






int main()
{
	int n[30];
	int count;
	bool prime[1000000];
	for (int i = 0; i < 30; i++) {
		cin >> n[i];
		count = 0;
		
		for (int i = 0; i <= n[i]; i++) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		for (int j = 2; j <= n[i]; j++) {
			if (prime[j]) {
				for (int k = 2 * j; k <= n[i]; k += j) {
					prime[k] = false;
				}
			}
		}

		for (int j = 1; j <= n[i]; j++) {
			if (prime[j]) count++;
		}
		cout << count << endl;


	}
	

}

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

int main(){
	bool is_prime[1000000];
	
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i < 1000000; i++){
		is_prime[i] = true;
	}
	for(int i = 2; i * i < 1000000; i++){
		if(is_prime[i]){
			for(int j = i * i; j < 1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}
	
	int n_prime[1000000];
	int cnt = 0; 
	for(int i = 0; i < 1000000; i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i] = cnt;
	}
	while(true){
		int n;
		cin >> n;
		if(cin.eof()){
			break;
		}
		cout << n_prime[n] << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int i,j;
	char array[1000010];
	
	for(i=0;i<1000001;i++)
		array[i]='1';
	
	array[0]=array[1]='0';
	
	for(i=0;i<1000001;i++)
	{
		if(array[i]=='1')
		{
			for(j=2;i*j<1000001;j++)
				array[i*j]='0';
		}
	}
	
	vector<int> ans;
	
	for(i=0;i<1000001;i++)
	{
		ans.push_back(0);
	}
	for(i=1;i<1000001;i++)
	{
		ans[i]+=ans[i-1];
		ans[i]+=(int)array[i]-48;
	}
	
	int inp;
	
	cin >> inp;
	cout << ans[inp] << endl;
}