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++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i])  {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }
  prime.erase(remove(prime.begin(), prime.end(), 0), prime.end());
  return prime;
}

int main() {
  int n;
  vector<int> prime;
  prime = sieve(1000000);

  while(cin >> n) {
    int count=0;

    for(vector<int>::iterator it=prime.begin(); it!=prime.end(); it++) {
      if(*it>n) break;
      count++;
    }
    cout << count <<endl;
  }
  return 0; 
}

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

#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))
#define mnv(v) (*min_element(v.begin(), v.end()))
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef string S;
typedef int I;

int x = 1000001 ;
bool prime[1000001] ;

void sev(){
    
    for(int i = 2; i*i <= x; i++)
    {
        
        for(int j = i*2; j <= x; j+=i)
        {
            prime[j] = true ;
        }
        
    }
    
}

int main()
{
    sev() ;
    I n ;
    while(cin >> n){
        int c = 0 ;
        for(int i = 2; i <= n; i++)
        {
            if(!prime[i]){
                c++ ;
            }
        }
        cout << c << endl ;
        
    }
    return 0;
}

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

bool prime(int n){
	for(int i=2;i<=(n/2);i++){
		if((n%i)==0){
			return false;
		}
	}
	return true;
}

int main(){
	int N =1000000;
	int n;
	int *data;
	data = new int[N];

	for(int i=0; i<N; i++){
		data[i] = -2;
	}
	data[0]=0; data[1]=0;


	for(int i=2;i<N;i++){
		if(prime(i)==true){
			data[i] = data[i-1]+1;
		}else{
			data[i]=data[i-1];
		}

//		if(i%(N/100)==0) cout << ".";

	}

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

	return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    ll n;
    while(cin>>n){
        vector<bool> ip;
        if(ip.size()<n+1){
            ip.resize(n+1,true);
        }
        ip[0]=false;
        ip[1]=false;
        for(int i=2;i<n+1;i++){
            for(int j=2;i*j<n+1;j++){
                ip[i*j]=false;
            }
        }
        ll ans=0;
        for(int i=0;i<n+1;i++){
            if(ip[i])ans++;
        }
        
        
        cout<<ans<<endl;
        
        
        
    }





return 0;
}

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

static const long MAX = 1000000L;
 
int main() {
    vector<long> prime;
    vector<long> dp;
    bool isPrime;
    long n, m;
 
    long i, len = sqrt(MAX) + 1;
    long j, lenJ;
    long k;
     
    prime.push_back(2);
    dp.push_back(0);
	dp.push_back(0);
	dp.push_back(1);

    for (i = 3; i <= len; i += 2) {
        isPrime = true;
        lenJ = prime.size();
        k = sqrt(i) + 1;
        for (j = 0; j < lenJ; j++) {
            if (k <= prime[j]) break;

            if (i % prime[j] == 0) {
                isPrime = false;

                break;
            }
	}

        if (isPrime) prime.push_back(i);
    }

    lenJ = prime.size();
     
    while (cin >> n) {
	if (n < dp.size()) {
		cout << dp[n] << endl;

		continue;
	}
         
	m = dp.size();
        for (i = m; i <= n; i += 2) {
            isPrime = true;

            k = sqrt(i) + 1;
            for (j = 0; j < lenJ; j++) {
                if (k <= prime[j]) break;

                if (i % prime[j] == 0) {
                    isPrime = false;

                    break;
                }
            }

            if (isPrime) {
		dp.push_back(dp.back() + 1);
		dp.push_back(dp.back());
	    } else {
		dp.push_back(dp.back());
		dp.push_back(dp.back());
	    }
        }
         
        cout << dp[n] << endl;
    }
 
    return 0;
}

C++: #include<iostream>
#include<math.h>
#include<fstream>
using namespace std;
int Test(int n);
int  main()
{
	fstream f;
	int n;
	f.open("taptin.txt", ios::in);
	f>>n;
	f.close();
	f.open("Ketqua.txt",ios::out);
	int t=0;
	if( n == 2)
	{
		t=1;
	}
	else
	{
		t =1;
		for(int i = 3 ; i <= n ; i= i+2)
		{
			if(i % 6 !=0)
			{
				if(Test(i)==1)
				{
					t= t+1;
				}
			}
		}
	}
	f<<t;
	f.close();
	return 0;
}
int Test(int n)
{
	for(int i = 2 ; i <= sqrt((float)n) ; i++)
	{
		if( n % i == 0)
			return 0;
	}
	return 1;
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	int i;
	int flag;
	int ans;
	
	while (scanf("%d", &n) != EOF){
		
		ans = 0;
		while (n >= 2){
			flag = 0;
			for (i = n - 1; i >= 2; i--){
				if (n % i == 0){
					flag = 1;
				}
			}
			
			if (flag == 0){
				ans++;
			}
			
			n--;
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include<stdio.h>
int num[999999];
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=999999;i++)
	num[i]=1;
for(int i=2;i<=999999;i+=2){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

C++: #include <cmath>
#include <cstdio>
 
inline bool fermat_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
    }
}
 
inline bool prime_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
            if ((n %= i) == 0) {
                return false;
            }
        }
    }
    return true;
}

unsigned short v[999999];

int main() {
    int n;
    v[3] = 2;
    while (~scanf("%d", &n)) {
        for (int i = 5; i <= n; i += 2) {
            if (v[i] > 0)
                continue;
 
            v[i] = v[i - 2] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", v[n % 2 == 0 ? n - 1 : n]);
    }
}