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 <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
/*int main(){
    
    ll n;
    while (cin>>n) {
        vector<ll> v;
        for(int i=0;i<n+1;i++){
            v.push_back(i);
        }
        ll b=v[v.size()-1];
        for(int i=2;i<=n;i++){
            ll j=2;
            while(i*j<=b){
                v[i*j]=0;
                j++;
            }
        }
        ll ans=0;
        for(int i=0;i<v.size();i++){
           // cout<<v[i]<<endl;
            if(v[i]!=0)ans++;
        }
        cout<<ans-1<<endl;
    }
    
    
    return 0;
}*/
int main(){
    
    ll n;
    while(cin>>n){
       /* ll ans=0;
        for(int i=3;i<=n;i+=2){
            int flag=0;
        for(int j=3;j<=sqrt(i);j+=2){
            if(i%j==0){
                flag=1;
                break;
            }
        }
            if(flag==0){
                ans++;
            }
    }
        cout<<ans+1<<endl;*/
        
        vector<bool> IsPrime;
        if(n+1>IsPrime.size()){
            IsPrime.resize(n+1,true);
        }
        IsPrime[0]=false;
        IsPrime[1]=false;
        for(int i=2;i<=sqrt(n);i++){
            if(IsPrime[I]){
                for(ll j=2;i*j<=n;++j){
                    IsPrime[i*j]=false;
}
        }
        
        }
        ll ans=0;
        for(int i=0;i<IsPrime.size();i++){
            if(IsPrime[i])ans++;
        }
        cout<<ans<<endl;
        }
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n,i,j;
	cin>>a;
	n=0;
	for(i=2;i<=a;i++){
		for(j=2;j<i;j++){
			if(i%j==0)break;
		}
		if(i == j) n += 1;
	}
	cout<<n<<endl;
}

C++: #include <iostream>

int prime_number_count(const int n)
{
    int cnt;
    bool was_not_divisible;
    
    if (n < 2){
        return 0;
    }
    
    cnt = 1;
    for (int i = 3; i <= n; i += 2){  // dividend: 被除数
        was_not_divisible = true;
        for (int j = 3; j * j <= i; j += 2){  // divisor: 除数
            if (i % j == 0){
                was_not_divisible = false;
                break;
            }
        }
        if (was_not_divisible){
            cnt++;
        }
    }
    
    return cnt;
}

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

C++: #include <iostream>
#include <cmath>
#define MAX 1000000
using namespace std;

int main() {
	int n, count;
	bool a[MAX];
	for (int i = 2;i < MAX;i++) { a[i] = true; }
	for (int i = 2;i < sqrt(MAX);i++) {
		if (a[i] ==true) {
			for (int j = 2;j*i < MAX;j++) { a[j*i] = false; }
		}
	}
	
	while (cin >> n) {
		count = 0;
		for (int i = 2;i <= n;i++) {
			if (a[i])
				count++;
		}
		cout << count << endl;
	}
}

C++: #include <stdio.h>

int main(){
	int sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0)break;
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

const int max=500000;
int prime[max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<max; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<max; j+=i) prime[j]=0;
    }
    for(int i=1; i<max; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main() {
	int n,ans=0,i,count=0;
	while (cin >> n) {
		for (i = 2; i <= n; i++) {
			for (int j = 2; j <= i; j++) {
				if (i%j == 0) {
					count++;
				}
			}
			if (count == 1) {
				ans++;
			}
			count = 0;
		}
		cout << ans << endl;
		ans = 0;
	}
	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;

	while(cin >> input){
	cout << CheckNum(input) << endl;
	}
}

C++: #include <iostream>

using namespace std;

const int MAX = 1000000;
bool p[MAX];
int num[MAX];

void prepare() {
    for (int i=0; i<MAX; ++i) p[i] = true;
    p[0] = p[1] = false;
    for (int i=2; i*i<MAX; ++i) {
        if ( ! p[i]) continue;
        for (int j=i*i; j<MAX; j+=i) {
            p[j] = false;
        }
    }
    int sum = 0;
    for (int i=0; i<MAX; ++i) {
        if (p[i]) sum ++;
        num[i] = sum;
    }
}

int main() {
    prepare();
    int n;
    while (cin >> n) {
        cout << num[n] << endl;
    }
    return 0;
}

C++: #include <cstdio>
const int N=1000000;
bool p[N];int pN[N];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)p[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i]=c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		if ( n <= 0 )
			cout << "0" << endl;
		
		vector <bool> p(n+1, true);

		p[0] = p[1] = false;
		for ( int i = 4; i <= n; i += 2 )
		{
			p[i] = false;
		}

		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
			{
				for ( int j = i+i; j <= n; j += i )
				{
					p[j] = false;
				}
			}
		}

		int kotae = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
				kotae++;
		}

		cout << kotae << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;
int main(){
	bool n[1000000];
	for(int i=0; i<1000000; i++){ n[i]=1; }
	n[0]=0;
	n[1]=0;

	for(int i=2; i<1000000; i++){
		if(n[i]==0){ break; }
		if(n[i]==1){
			for(int j=i*2; j<1000000; j+=i){ n[j]=0;	}
		}
	}

	int num;
	int count;
	while(cin >> num){
		count = 0;
		for(int i=2; i<=num; i++){
			count += n[i];
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		i = 3;
		cnt = 0;
		fg = 0;	
		
		if ((int)log10(n) == 3) {
			cnt = 167;
			i = 1001;
		}
		else if ((int)log10(n) == 4) {
			cnt = 1228;
			i = 10001;
		}
		else if ((int)log10(n) == 5) {
			cnt = 9591;
			i = 100001;
		}
		else if ((int)log10(n) == 6) {
			cnt = 78497;
			i = 1000001;
		}


		for (; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		if (n >= 2)
			cnt++;
		cout << cnt << endl;
	}

	return 0;
}