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<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;
}

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

int main()
{
	int testcase, i;

	scanf("%d", &testcase);	
	for (i=0; i<testcase; i++)
	{
		int num, j=2, count = 0;				
		scanf("%d", &num);

		int* check = (int*) malloc(sizeof(int)*num);			

		int k;
		for (k=0; k<num; k++)
		{
			check[num] = 0;
		}

		if (num == 2)
		{
			count++;
		}
		for (j=j; j<num; j++) 
		{
			if (check[j] == 1)
				continue;
			
			count++;

			int l;		
			for (l=2; l * j < num; l++)
			{				
				check[j * l] = 1;
			}			
		}
		printf("%d\n", count);
		free(check);
	}

	return 0;
}

C++: #include<iostream>
#include<math.h>
main(){int i,j,n,p[1000000];std::cin>>n;for(i=2;i<=n;i++)p[i]=1;for(i=2;i<n;i++)if(p[i])for(j=2;i*j<=n;j++)p[i*j]=0;j=0;for(i=2;i<=n;i++)j+=p[i];std::cout<<j<<std::endl;}

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

int main(){

  int n;
  int a,b,i;
  int sosu[N];
  bool judge;

  sosu[0] = 2;
  for(a=3,i=1;a<1000000;a++){
    judge = true;
    for(b=0;sosu[b]*sosu[b] <= a;b++){
      if(a%sosu[b] == 0){
	judge = false;
	break;
      }
    }
    if(judge){
      sosu[i] = a;
      i++;
    }
  }
  while(cin >> n){
    for(i=0;sosu[i]<=n;i++);
    cout << i << endl;
  }

  return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int manko = 0;
		for(int i = 2; i <= n; i++){
			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) manko++;
		}
		cout << manko << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    const int N = 1000000;

    static bool P[N];
    for (int i=2; i<N; i++)
        P[i] = true;
    for (int i=2; i<N; i++)
        if (P[i])
            for (int j=i+i; j<N; j+=i)
                P[j] = false;

    static int A[N];
    for (int i=1; i<N; i++)
        A[i] = A[i-1] + int(P[i]);

    int n;
    while (cin>>n)
        cout<<A[n]<<endl;
}

C++: #include<stdio.h>
using namespace std;
const int maxn=1e6+1;
int prime[maxn];
int main(){
	for(int i=2;i*i<=maxn;i++){
		if(!prime[i]){
			for(int j=2*i;j*j<=maxn;j+=i)
			prime[j]=1;
		}
	}
	int n,flag;
	while(scanf("%d",&n)!=EOF){
		flag=0;
		for(int i=2;i<=n;i++)
		if(!prime[i])
		flag++;
		printf("%d\n",flag);
	}
	return 0;
}