Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

int main(int argc, const char * argv[])
{
    int count=0;
    int i=1;
    int n=1;
    int number;
    // insert code here...
    while (cin >> number, number != EOF){
        while (n <= number){
            if(n == 1) {n++; continue;}
            while (i <= n) {
                if(i == 1) {i++; continue;}
                if(i == n) count++;
                if(n % i == 0) break;
                i++;
            }
            n++;
            i=1;
        }
        i=1;
        n=1;
        cout << count << endl;
        count = 0;
    }
    
    return 0;
}

C++: #include <stdio.h>
int prime[1000001];
int main(){
  int i, k, n,cnt = 0;
  for(i = 2; i <= 1000000; i++){
    prime[i] = 1;
  }
  for(i = 2; i*i <= 1000000; i++){
    if(prime[i]){
      for(k = 2 * i; k <= 1000000; k += i){
        prime[k] = 0;
      }
    }
  }
  while(1){ 
    scanf("%d", &n);
    if(n == 0) break;
    for(i = 2; i <= n; i++){
      if(prime[i] == 1){
        cnt++;
      }
    }
    printf("%d\n",cnt);
    cnt = 0;
  }
  return 0;
}

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

int main(){
	bool x[1000000];
	int cou, num;
	
	while(cin >>num){
		cou = 0;
		for(int i = 2; i <= num; i++){
			x[i] = true;
		}
		for(int i = 2; i <= sqrt(num); i++){
			if(x[i]){
				for(int j = (i * 2); j <= num; j += i){
					x[j] = false;
				}
			}
		}
		
		for(int i = 0; i <= num; i++){
			if(x[i]){
				cou++;
			}
		}
		
		cout <<cou<<endl;
	}
	
	return 0;
}

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

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

int main(){
	int n;
	while(cin>>n){
		int manko = 0;
		for(int i = 1; i <= n; i += 2){
			int ans = 1;
			for(int j = 2; j <= i/j ; j++){
				if(i % j == 0){
					ans += j + i/j;
				}
				if(i == j*j)ans -= j;
				if(ans > 1) break;
			}
			if(ans == 1) manko++;
		}
		cout << manko << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
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*i<=x) {
        if (x%i==0) {
            return false;
        }
        i+=2;
    }
    /*for (int i=3; i*i<=x; i+=2) {
     if (x%i==0) {
     return false;
     }
     }*/
    return true;
}
int main() {
    int n;
    int cnt;
    while (cin >> n) {
        cnt=0;
        for (int i=0; i<=n; i++) {
            if (isPrime(i)) {
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,x,i;
	while((scanf("%d",&a))!=EOF){
		x=0;
		for(i=2;i<a+1;i++){
			if(i%2!=0&&i%3!=0&&i%5!=0&&i%7!=0){
				x++;
			}
			else if(i==2||i==3||i==5||i==7){
				x++;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

C++: /*#include<stdio.h>

int checkPrime(int i)
{
     int p;
    for ( p = 2 ; p <= i - 1 ; p++ )
    {
        if ( i%p == 0 )
            return 0;
    }
    if ( p == i )
        return 1;
}
int main()
{
    int n,sum=0,count=0,rem,i;
    while(scanf("%d",&n)!= EOF){
        for(i=2;i<n-1;++i)
        {
           if(checkPrime(i)==1);
              count++;

        }
        printf("%d",count);
    }
    return 0;
}

/*#include<stdio.h>

int main()
{
   int n, i = 3, count, c;

   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);

   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }

   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }

   return 0;
}
*/
/*#include<stdio.h>
#include<math.h>
int main(){

    int n;
    while(scanf("%d",&n)!=EOF){
    int num,i,count=0;
    for(num = 2;num<=n;num++){
         int flag = 1;
         int len = (int) (sqrt(num));
         //printf("%d\n",len);
         for(i=2;i<=len;i++){
             if(num%i==0){
                flag = 0;
                 break;
             }
        }
        if(flag==1)
            count++;
    }
    printf("%d\n",count);
    }

   return 0;
}

*/
#include<stdio.h>
#include<string.h>

bool mark [1000000];
 void sieve ()
 {
    int N = 1000000;
    memset (mark, true, N + 2);

    mark [0] = mark [1] = false;

    for ( int i = 4; i < N + 2; i += 2 )
        mark [i] = false;

    for ( int i = 3; i * i <= N + 2; i += 2 ) {
        if ( mark [i] == true ) {
            for ( int j = i * i; j < N + 2; j += 2 * i )
                mark [j] = false;
        }
    }
 }
int main()
{
    int n;
    sieve();
    while(scanf("%d",&n)!=EOF){
        int count = 0,i;
        for(i=2;i<=n;++i)
        {
            if(mark[i]==true)
                count++;
        }
        printf("%d\n",count);
   }
}

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

int main(){
    int n;
    vector<int> S;
    
    while(cin>>n){
        S.push_back(2);
        int ans=0;
        for(int i=3; i<=n; i++){
            int judge=0;
            for(int j=0; j<S.size(); j++){
                if(i%S[j]==0)judge=1;
            }
            if(judge==0){
                ans++;
                S.push_back(i);

            }
        }
        cout<<ans+1<<endl;
        S.clear();
    }
    return 0;
}

C++: #include <stdio.h>

int sieve(int n)
{
	char prime[100000];
	int i, j;
	int p;
	
	for (i = 0; i <= n + 1; i++){
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;
	
	for (i = 2; i <= n + 1; i++){
		if (prime[i]){
			for (j = 2 * i; j <= n; j += i){
				prime[j] = 0;
			}
		}
	}
	for (i = 0, p = 0;i <= n; i++){
		if (prime[i] == 1){
			p++;
		}
	}
	
	return (p);
}

int main(void)
{
	int num;
	int ans;
	
	while (scanf("%d", &num) != EOF){
		ans = sieve(num);
		
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
void init(bool* table){
	for (int i = 2; i < 100000; i++){
		for (int j = 2; j < 100000/i; j++){
			*(table + i*j) = false;
		}
	}
}
int main(){
	int num;
	bool table[100000];
	for (int i = 0; i < 100000; i++){
		table[i] = true;
	}
	init(table);
	while (cin >> num){
		int cnt = 0;
		for (int i = 2; i <= num; i++){
			if (table[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
	int n;
	int a[100000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}