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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

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

int main() {
	int n,yakusuu,sosuu;
	while (cin >> n) {
		sosuu = 0;
		for (int i = 1; i <= n; i++) {
			yakusuu = 0;
			for (int j = 1; j <= i; j++){
				if (i%j == 0)yakusuu++;
			}
			if (yakusuu == 2)sosuu++;
		}
		cout << sosuu << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n,i,j,buf,cnt;
	bool flag;

	while(cin >> n){
		cnt = 1;
		for(i=3;i<=n;i+=2){
			flag = false;
			buf = (int)sqrt((double)i);

			for(j=3;j<=buf;j+=2){
				if((i % j) == 0){
					flag = true;
					break;
				}
			}

			if(flag == false){
				cnt++;
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

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

int main(){
    int n, cnt;
    bool prime[1000000];
    prime[0] = prime[1] = false;
    
    for(int i = 2;i <= 1000000;i++){
        prime[i] = true;
    }

    while(cin >> n){
        cnt = 0;
        
        for(int i = 2;i <= sqrt(n);i++){
            if(prime[i]){
                for(int j = 2*i;j<= n;j++){
                    if(j%i == 0){
                        prime[j] = false;
                    }
                }
            }
        }
        
        for(int i = 2;i <= n;i++){
            if(prime[i]){
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }

    return 0;
}

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

#define Max 999999

int main(){
	bool is_prime[Max+1];
	for(int i=0;i<=Max;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=Max;i++){
		if(is_prime[i]){
			for(int j=i*2;j<=Max;j+=i)is_prime[j]=false;
		}
	}
	int n;
	while(std::cin>>n){
		int count=0;
		for(int i=2;i<=n;i++){
			if(is_prime[i])count++;
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	int n;
	cin >> n;
	
	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] )
		{
			cout << i << endl;
			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<bits/stdc++.h>
using namespace std;

vector<int> sieve;

void make_prime(){
  bool a[1000001];
  for(int i = 0; i <= 1e6; i++)a[i] = false;
  a[0] = true;
  a[1] = true;
  for(int i = 2; i <= 1e6; i++){
    if(a[i])continue;
    sieve.push_back(i);
    for(int j = i; j <= 1e6; j += i){
      a[j] = true;
    }
  }
}

int main(){
  int n;
  make_prime();
  while(cin >> n){
    int cnt = 0;
    for(int i = 0; sieve[i] <= n; i++)cnt++;
    cout << cnt << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
using namespace std;
int main()
{
	    int n;
		bool a[1000001]; 
		memset(a,0,sizeof(a));
		for(int i=2;i<=1000;++i)
		{
			for(int j=2;j*i<=1000000;++j)
			{
				a[i*j]=1;
			}
		}

	while(cin>>n)
	{
		int count=0;
		for(int k=2;k<=n;k++)
		{
			if(!a[k])
			count++;
		}
		cout<<count<<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<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<ctype.h>
#include<math.h>
#include<map>
#include<time.h>
using namespace std;
const int N=1e6;
int isprime[N];
int prefixsum[N];
int SQRT=ceil(sqrt((double)N));		//返回大于或者等于指定表达式的最小整数 
int prime()
{
	memset(isprime,1,sizeof(isprime));
	int i;
	isprime[0]=isprime[1]=0;
	for(i=0;i<=SQRT;i++)
	{
		if(isprime[i])
		{
			for(int j=i*i;j<=N;j+=i)
			{
				isprime[j]=0;
			}
		}
	}
}
void maketable()
{
	for(int i=1;i<N;i++)
	{
		prefixsum[i]=isprime[i]?prefixsum[i-1]+1:prefixsum[i-1];
	}
} 
int main()
{
	prime();
	maketable();
//	printf("%.2f\n",(double)clock()/CLOCKS_PER_SEC);
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",prefixsum[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

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

	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		int c = 0;
		if ( n == 2 )
			c = 1;
		else if( n < 2 )
			c = 0;
		else
		{
			c = 1;
			for ( int i = 3; i <= n; i += 2 )
			{
				if ( primes[i] )
					c++;
			}
		}

		cout << c << endl;

	}

	return 0;
}

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

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int mx = 1000010;
  vector<bool> isp(mx,true);
  isp[0]=false;
  isp[1]=false;
  REP(i,mx){
    if(isp[i]==false)continue;
    int t = i*2;
    while(t<mx){
      isp[t] = false;
      t += i;
    }
  }
  vector<int> sum(mx,0);
  REPR(i,mx) sum[i] = sum[i-1] + isp[i];
  int n;
  while(~scanf("%d",&n))cout<<sum[n]<<endl;
  return 0;
}

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

int main(void)
{
	bool prime[1000000];
	unsigned long n;

	for(unsigned long j = 2; j <= 999999; j++)
		prime[j] = true;
	for(int i = 2; i <= 1000; i++) {
		if(prime[i] == true) {
			for(unsigned long j = i * i; j <= 999999; j += i) {
				prime[j] = false;
			}
		}
	}

	while(cin >> n) {
		unsigned cnt = 0;
		for(unsigned long j = 2; j <= n; j++) {
			if(prime[j] == true) {
				cnt++;
			}
		}

		cout << cnt << endl;
	}
	return 0;
}