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<bits/stdc++.h>
using namespace std;

int f[1000001];
int main(){
    fill_n(f,f+1000001,1);
    f[0]=f[1]=0;
    
    for(int i=2;i<1000001;i++){
        f[i]+=f[i-1];
        if(!f[i])continue;
        for(int j=i+i;j<1000001;j+=i)f[j]=0;
    }
    
    int N;
    
    while(scanf("%d",&N),&N){
        printf("%d\n",f[N]);
    }
    
    return 0;
    
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	int *prime = new int[n];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

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

using namespace std;

bool N[999999];

int FindPrime(int n) {
  int ans = 0;
  for(int i = 1; i <= sqrt(n); i++) {
    if(N[i - 1]) {
      for(int j = 2; j <= n / i; j++) {
        N[i * j - 1] = false;
      }
    }
  }

  for(int i = 0; i < n; i++) {
    if(N[i]) {
      ans++;
    }
  }

  return ans;
}

int main() {
  int n;
  while(cin >> n) {
    for(int i = 1; i < n; i++) {
      N[i] = true;
    }

    int ans = FindPrime(n);

    cout << ans << endl;
  }

  return 0;
}

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


bool isPrime(int I)
{
	int b = sqrt (I*1.0) + 1;
	for(int i = 2; i < b; i ++){
		if(I % i == 0)
			return false;
	}
	return true;
}
void printPrime(int N)
{
	int total = 0;
	for(int i = 2; i <= N; i ++)
	{		
		if(isPrime(i) == true){
			total ++;
		}
	}
	cout<<total<<endl;
}


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

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

int main() {
	
	int n;
	int count;
	int *prime;
	
	
	while( cin >> n ){
		prime = new int[n];
		count = 1;
		
		prime[0] = 2;
		
		for(int i=3;i<=n;i+=2){
			int isPrime = true;
			
			for(int j=0;j<count;++j){
				if(i%prime[j] == 0){
					isPrime = false;
					break;
				}
			}
			
			if(isPrime){
				prime[count] = i;
				count++;
			}
		}
		
		cout << count << endl;
		
		delete[] prime;
	}
	
	return 0;
}

C++: #include<iostream>
#include <math.h>
#include <vector>
using namespace std;
int count=0,num=0;
int main()
{
	while(cin>>num)
	{
		count=0;
		vector<bool> a(num+1,true);
		for(int i=2;i<=sqrt(num);i++)
		{
			
			if(a[i]==true)
				for(int j=i*i;j<=num;j+=i)
				{
					
					a[j]=false;
				}
				
		}
		for(int  i=2;i<=num;i++)
		{
			cout<<a[i];
			if(a[i]==true)
				count++;
		
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int hako[1000100];
int main(){
	int n;
	while(cin >> n){
		int ret = 0;
		REP(i,1000100)hako[i] = 0;
		for(int i=2;i<=n;i++){
			if(hako[i] == 1)continue;
			ret++;
			for(int j=i;j <= n;j+=i){
				hako[j] = 1;
			}
		}
		cout << ret << endl;
	}
	return 0;
}

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

#define MAX 1000000



int main(void){

	bool p[MAX+1];
	int n,ans;

	for(int i=0;i<=MAX;i++){
		p[i]=(i<=1)?false:true;
	}

	for(int i=2;i<=(sqrt((double)MAX))+1;i++){
		if(p[i]){
			for(int j=i*2;j<=MAX;j=j+i){
				p[j]=false;
			}
		}
	}

	while(cin>>n){
		ans=0;
		for(int i=0;i<=n;i++){
			if(p[i]){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>                                             
using namespace std;                                            
                                                                
bool IsPrime(int n) {                                           
  if (n==2) {                                                   
    return true;                                                
  }                                                             
  if (n<2 || n%2==0) {                                          
    return false;                                               
  }                                                             
  for (int k=3; k*k<=n; k+=2) {                                 
    if (n%k==0) {                                               
      return false;                                             
    }                                                           
  }                                                             
  return true;                                                  
}                                                               
                                                                
int main() {                                                    
  int n;                                                        
  while (cin >> n) {                                            
    int ans = 0;                                                
    for (int i=0; i<=n; i++) {                                  
      if (IsPrime(i)==true) {                                   
        ans++;                                                  
      }                                                         
    }                                                           
    cout << ans << endl;                                        
  }                                                             
  return 0;                                                     
}

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

using namespace std;

const int N_MAX = 1000000;

int table[N_MAX];

int main() {
  for (int i = 0; i < N_MAX; i++) {
    table[i] = 0;
  }
  table[0] = table[1] = 1;
  int sq = sqrt(N_MAX);
  for (int i = 2; i < sq+1; i++) {
    if (table[i] == 0) {
      for (int j = i*2; j < N_MAX; j += i) {
        table[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {

    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (table[i] == 0) ans++;
    }
    cout << ans << endl;

  }

  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define MAX_N 100001
int main(){
	int n;
	while(cin >> n){
		vector<int> vec;
		vector<int>::iterator it =vec.begin();
		for(int i=2;i<=n;i++){
			int flag=0;
			it =vec.begin();
			while(it!= vec.end()){
				if(i% *it==0){
					flag=1;
					break;
				}
				it++;
			}
			if(!flag)vec.push_back(i);
		}
		it =vec.begin();
		//while(it!= vec.end()){
		//	cout<<*it<<endl;
		//	it++;
		//}
		cout << vec.size()<<endl;
	}