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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N_MAX 100000

using namespace std;

int main(){
	
	int array[N_MAX],i,j,n, num = 0;
	
	while(cin>>n){
		num = 0;
		for (i=0;i<n;i++)
			array[i]=i+2;
		for (i=0;i<n;i++){
			for (j = (i+2); (i+2) * j <= n; j++)
				array[(i+2) * j - 2] = -1;}

	for (i = 0; i < n-1; i++){
    if (array[i] != -1)
	num++;
	}
	cout<<num<<endl;
	}
	cin>>n;
  
	return (0);
}

C++: #include<iostream>

int n;
bool *isPrime;

int solve(){
	int p = 0;
	for(int i=0; i<=n; i++)
		isPrime[i] = true;
	isPrime[0] = isPrime[1] = false;
	for(int i=2; i<=n; i++){
		if(isPrime[i]){
			p++;
			for(int j=2*i; j<=n; j+=i)
				isPrime[j] = false;
		}
	}
	return p;
}

int main(){
	while(std::cin >> n){
		isPrime = new bool[n+1];
		std::cout << solve() << std::endl;
		delete[] isPrime;
	}
	return 0;
}

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

#define MAX (1000000)

int main(void)
{
	char prime[MAX + 1];
	int n;
	char buf[256];
	
	memset(prime, 1, sizeof(prime));
	
	prime[0] = prime[1] = 0;
	for (int i = 2; i * i < MAX; i++){
		if (prime[i] == 1){
			for (int j = i * 2; j <= MAX; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (fgets(buf, 256, stdin) != NULL){
		int ans;
		
		n = atoi(buf);
		
		ans = 0;
		for (int i = 2; i <= n; i++){
			ans += prime[i];
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

bool sieve[1000000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=0;i<=n;i++)
		{
			ans+=sieve[i]?1:0;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	for(int i=0;i<1000000;i++){sieve[i]=true;}
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<1000000;i++)
	{
		for(int j=i*2;j<1000000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

C++: #include <iostream>
using namespace std;
int main() {
	int n, count = 0;
	while(cin >> n) {
		for(int i = 2; i < n + 1; i++) {
			count++;
			for(int j = 2; j <= i / 2; j++) {
				if(i % j == 0) {
					count--;
					break;
				}
			}
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = 1000000+1000;
const int maxn=100000+5;
int prime[maxn+1];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt]=i;
       	cnt++;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	/*for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";*/
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}

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

int main(){

int i,j,n,count;

while(scanf("%d",&n) != EOF){

count=2;

if(n<4){
	count=n-1;
}else{
	for(i=4;i<n+1;i++){
		for(j=2;j<i/2+1;j++)

			if(i%j==0){
				break;
			}else if(j==i/2)
				count+=1;
	}
}

printf("%d\n",count);

}
return 0;		
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000001] = {false};
  for(int i=2; i<1000; i++){
    if(!num[i]){
      for(int j=i*i; j<1000001; j+=i){
	num[j] = true;
      }
    }
  }
  int n;
  while(cin >>n){
    int sum = 0;
    for(int i=2; i<=n; i++){
      if(!num[i]){sum++;}
    }
    cout <<sum<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  
  while(!cin.eof()) {
    cin >> n;
    list<int> search_list(n-1);
    list<int> prime_number;
    while(n!=1) {
      search_list.push_front(n);
      n--;
    }
    while(!search_list.empty()) {
      int m = search_list.front();
      prime_number.push_back(m);
      search_list.pop_front();
      list<int>::iterator it = search_list.begin();
      while(it!=search_list.end()) {
	if((*it % m) == 0){
	  it = search_list.erase(it);
	  continue;
	}
	it++;
      }				   
    }
    cout << prime_number.size() << endl;
    prime_number.clear();
    search_list.clear();
  }
}

C++: #include<iostream>
using namespace std;
int main(){
	bool num[1000000] = {0};
	for(int i=2; i<1000000; i++){
		if(!num[i]){
			for(int j=i*2; j<500000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

C++: #include <iostream>

using namespace std;
int main(){
	bool n[1000000];
	for(int i=0; i<1000000; i++){ n[i]=1; }
	n[0]=0;
	n[1]=0;

	for(int i=2; i<1000000; i++){
		if(n[i]==0){ break; }
		if(n[i]==1){
			for(int j=i*2; j<1000000; j++){ n[j]=0;	}
		}
	}

	int num;
	int count;
	while(cin >> num){
		count = 0;
		for(int i=2; i<=num; i++){
			count += n[i];
		}
		cout << count << endl;
	}

	return 0;
}

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

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(cin >> n){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

  if(n%2==0)
    return false;

  else{
    for(int i=3; i<=sqrt(n); i+=2){
      if(n%i == 0)
	return false;
    }
  }

  return true;
}

C++: #include <bits/stdc++.h>
using namespace std;

long long i,j,sum[1000005],total,n;
bool a[1000005];


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	for(i=2; i<1000000; i++){
//		cout<<i<<'\n';
		if(a[i]==false){
			j=i*i;
			while(j<1000000){
				a[j]=true;
				j+=i;
			}
		}
	}
	
	a[1]=true;
	total=0;
	for(i=1; i<1000000; i++){
		if(a[i]==false){
			total++;
		}
		sum[i]=total;
	}
	while(cin>>n){
		cout<<sum[n]<<'\n';
	}
	
return 0;
}

C++: 
 int main()
 {
     int num, i, j;
     cout<<"Enter an Integer:"<<endl;
                  cin>>num;
                  
                  for(i=0; i<=num; i++)
                  {
                           for(j=2; j<=i; j++)
                           {
                                    if(i%j == 0)
                                    {
                                    break;
                                    }
                                    else if (i == j+1)
                                    {
                                     cout<<i<<endl;    
                                         }
                                    }
                           }
    
}

C++: #include <iostream>
using namespace std;
int main()
{
	int A[30] = {};
	int P[1000000] = {};
	int c = 0, j;
	for (int k = 2; k < 1000000; ++k){
		if (P[k] == 0){
			P[k] = ++c;
			for (j = 2; j * k < 1000000; ++j)
				P[j * k] = -1;
		}
		else if (P[k] == -1)
			P[k] = c;		
	}
	int k;
	while (cin >> k)
		cout << P[k] << "\n";
	return 0;
}