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>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,sum;
    int b[999999];
    b[0]=0;
    for(int i=1;i<999999;i++){
        b[i]=prime(i+1);
    }
    while ( cin >> a){
        sum =0;
        for (int i=1;i<a;i++){
            sum +=b[i];
        }
        cout << sum << endl;
    }
}
int prime(int x){
    if(x==1)
        return 0;
    if(x==2 || x==3 || x==5 || x==7)
        return 1;
    if(x%2==0 || x%3==0)
        return 0;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 0;
    }
    return 1;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int prime[1000000];
bool is_prime[100001];

int sieve(int 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]==true){
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }
  return p;
}

int main(){
  int n;
  while(scanf("%d",&n)!=EOF)
    cout<<sieve(n)<<endl;
  return 0;
}

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

int prime[1000000] = {1};

int main()
{
  int n;
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 1000000; i++){
    if (prime[i] == 1){
      for (int j = 2 * i; j < 1000000; j += i){
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 1000000; i++){
    prime[i + i] += prime[i];
  }
  while (cin >> n){
    cout << prime[n];
  }

  return 0;
}

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

int main(){
  int n;

  while(cin >> n){
    int cnt = 0;
    for(int i = 1; i <= n; i++){

      if(i % 2 == 0|| i % 3 == 0 || i % 5 == 0) continue;

      int yakusuu = 0;

      for(int j = 1; i <= i; j++){
        if(i % j == 0) yakusuu++;
      }

      if(yakusuu==2) cnt++;

    }
    cout << cnt + 3 - 1 << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[999999]={0,0,1,2},n,k=0,count=2;
	for(int i=4;i<999999;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){k++;break;}
		}
		if(k==1)count++;
		a[i]=count;
		k=0;
	}
	while(cin>>n)cout<<a[n]<<endl;
	return 0;
}

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

int main(){

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

	int res = 0;
	bool flg = true;
	for(int i=2;i<=n;i++){
	    flg = true;
	    for(int j=2;j*j<=i;j++){
		if(i % j == 0){
                    flg = false;
                    break;
            }
	    }
	    if (flg) res++;
	}
	cout << res << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#define MAX 1000010

int is_prime[MAX];

void sieve(){
  int i,j;
  for(i=0;i<=MAX;i++)is_prime[i]=1;
  is_prime[0]=is_prime[1]=0;
  for(i=2;i<=MAX;i++){
    if(is_prime[i]){
      for(j=2*i;j<=MAX;j+=i)is_prime[j]=0;
    }
  }
}

int main(){
  int a,i;
  int sum[MAX];
  sieve();
  for(i=0;i<MAX;i++)sum[i]=0;
  for(i=1;i<MAX;i++)sum[i]=sum[i-1]+is_prime[i];
  while(scanf("%d",&a)!=EOF){
    printf("%d\n",sum[a]);
  }
  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define NUM 1000000
int main(){
	long int n;
	int p[NUM],i,j,k,a,b;
	for(i=0;i<NUM;i++){
		p[i]=0;
	}
	for(i=2;i<NUM;i++){
		if(p[i]==0){
			p[i]=2;
			for(j=2;j<=(NUM/i);j++){
				p[i*j]=1;
			}
		}	
	}
	while(cin>>n){
		a=0;
		for(i=2;i<=n;i++){
			if(p[i]==2)a++;
		}
		cout<<a<<endl;
	}

    return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
#define ll long long
typedef pair<int, int> P;

bool prime[1000005];

void solve()
{
	REP(i, 1000005)prime[i] = true;
	prime[0] = prime[1] = false;
	for (int i = 2; i*i <= 1000000;i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; j*i <= 1000000; j++){
				if (prime[i*j] == true)prime[i*j] = false;
			}
		}
	}
}

int main()
{
	int n;
	while (cin >> n)
	{

		int ans = 0;

		solve();
		REP(i, n + 1){
			if (prime[i] == true){
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    bool isPrime[n_size];
    isPrime[0]=false; isPrime[1]=false;

    for(unsigned i=2;i<n_size;i++)
        isPrime[i] = true;

    for(unsigned i=2;i*i<n_size;i++){
        if(isPrime[i]){
            for(unsigned j=(i*i);j<n_size;j+=i)
                isPrime[j] = false;
        }
    }

    unsigned n_prime[n_size];

    unsigned cnt = 0;
    for(unsigned i=0;i<n_size;i++){
        if(isPrime[i])
            cnt++;
        n_prime[i] = cnt;
    }

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

    return 0;
}

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

int main() {
	int n;

	while (std::cin >> n) {
		std::vector<int> nums;
		++n;
		for (int i = 0; i < n; ++i) {
			nums.push_back(i);
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) < 2) continue;
			for (int j = nums.at(i) * 2; j < n; j += nums.at(i)) {
				nums.at(j) = 0;
			}
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) > 1) {
				++c
			}
		}
	}
	return 0;
}

C++: //36
#include<iostream>

using namespace std;

int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
	cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

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

bool isPrime(int x){
	if(x == 0 || x == 1) return false;
	for(int i=2;i<x;i++){
		if(x % i == 0) return false;
	}
	return true;
}

int main(void){
	int n;
	int ans = 0;
	
	cin>>n;
	for(int i=2;i<=n;i++){
		if(isPrime(i)) ans++;
	}
	printf("%d\n",ans);

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	long int n,f,k,i;
	int count;
	bool chk;
	scanf("%d",&n)!=EOF);
		count=0;
		for(i=2;i<=n;i++){
		
			chk=0;
			f=i/2;
			k=2;
		
			while(f>=k){
				if((i%k)==0){
					chk=true;
					break;
				}
				k++;
			}
		
			if(chk==false){
				count++;
			}
		}
		cout<<count<<endl;
	
}

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

int main(int argc, const char * argv[])
{
    long int n;
    while (cin >> n) {
        int pnm = 0;
        for (long int i = 2; i <= n; i++) {
            int cnt = 0;
            for (long int j = 2; j <= i; j++) {
                if (i % j == 0) {
                    cnt++;
                }
            }
            if (cnt == 1) {
                pnm++;
            }
        }
        cout << pnm << endl;
    }
    
    return 0;
}