Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2 || num == 5:
		return true
	case num < 2 || num%2 == 0 || num%5 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

int arr[123456];

int main()
{

    int n;
    while(scanf("%d",&n)==1){
            memset(arr,0,sizeof arr);
    int k=0;
    int s=sqrt(n+1);

    for(int i=4;i<=n;i=i+2)
    {
        arr[i]=1;
    }
    for(int i=3;i<=s;i++)
    {
        if(arr[i]==0)
        {
            for(int j=i*i;j<=n;j=j+i)
            {
                arr[j]=1;
            }
        }
    }

    for(int i=2;i<=n;i++)
    {
        if(arr[i]==0)
        {
            k++;
        }
    }
    cout<<k<<endl;

    }


    return 0;
}

C++: #include<iostream>



using namespace std;



int n;

int prime[1000000];

int checked[1000000];

int primesum[1000000];

int result[30];

int datasets;



int main()

{

	prime[0] = 0;

	prime[1] = 0;

	primesum[0] = 0;

	primesum[1] = 0;



	for (int a = 2; a<1000000; a++)

	{

		prime[a] = 1;

	}



	for (int a = 2; a<1001; a++)

	{

		if (checked[a] == 0)

		{

			checked[a] = 1;

			for (int b = 2; b<a; b++)

			{

				if (a%b == 0)

				{

					prime[a] = 0;

					break;

				}

			}

			if (prime[a] == 1)

			{

				for (int c = 2 * a; c<1000000; c += a)

				{

					checked[c] = 1;

					prime[c] = 0;

				}

			}

		}

	}



	for (int a = 2; a<1000000; a++)

	{

		primesum[a] = primesum[a - 1] + prime[a];

	}



	while (cin >> n)

	{

		cout << primesum[n] << endl;

	}



	return 0;

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int p[MAX];
void f(){
	int n=0;
	for(int i=2;i<MAX;i++){
		if(p[i]==0){
			p[i] = ++n;
			for(int j=2;j*i<MAX;j++)
				p[j*i] = -1;
		}
		else p[i] = n;
	}
} 
int main(){
	int n;
	f();
	while(cin>>n){	
		cout<<p[n]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define nINF -2147483648
using namespace std;
int p10(int x)
{
	int t=1;
	for (int i=1;i<=x;i++) t*=10;
	return t; 
}

bool a[1000000];
int s[1000000];
int main()
{
	int k,t=0;
	for (int i=2;i<=p10(3);i++)
	{
		k=2;
		while (i*k<p10(6))
		{
			a[k*i]=true;
			k++;
		}
	}
	for (int i=2;i<=p10(6);i++)
	{
		if (!a[i]) t++;
		s[i]=t;
	}
	while (cin>>k) cout<<s[k]<<endl;
	return 0;
}

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

#define MAX 1000000

int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}
	primes[2] = true;
	
	int n;
	while ( cin >> n )
	{
		int cnt = 0;
		for ( int i = 0; i <= n; ++i )
		{
			if ( primes[i] )
				cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

C++: import sys
import math as mas

def sieve(n):
	p=[True for i in range(n+1)]
	p[0]=p[1]=False
	end=int(n**0.5)
	for i in range(2,end+1):
		if p[i]:
			for j in range(i*i,n+1,i):
				p[j]=False
	return p
	
sosu=sieve(1000010)
for i in sys.stdin:
	t=int(i)
	if t<2:print(0)
	elif t==2:print(1)
	else:print(1+sum(sosu[t] for t in range(3,int(i)+1,2)))

#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

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

int main(){
	int n;
	int sosu[100000];
	int snum;
	bool judge;

	sosu[0] = 2;

	while(cin >> n){
		snum = 0;
		for(int i = 3; i <= n; i++){
			judge = true;
			for(int j = 0; sosu[j]*sosu[j] < i; j++){
				if(i%sosu[j] == 0){
					judge = false;
					break;
				}
			}
			if(judge == true){
				snum ++;
				sosu[snum] = i;
			}
		}
		cout << snum + 1 << endl;
	}



	return(0);
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int PrimeCount(int n){
	int count = 0;
	bool s;

	if (n > 2){
		count = 1;

		for (int i = 3; i <= n; i += 2){
			s = true;
			for (int j = 3; j <= sqrt(i); j += 2){
				if (i%j == 0){
					s = !s;
					break;
				}
			}

			if (s){
				count++;
			}
		}
	}



	return count;
}

int main(){
	ios::sync_with_stdio(false);

	int n;

	while (cin >> n){
		if (n == 1)
			cout << 0 << endl;
		else if (n == 2)
			cout << 1 << endl;
		else
			printf("%d\n", PrimeCount(n));
	}

}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

vi prime;
vector<bool> is_prime;

void sieve(number n) {
    is_prime.assign(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (number i = 2; i < n; ++i) {
        if (is_prime[i]) {
            prime.pb(i);
            for (number j = i + i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

int main() {
    int n; 
    sieve(1010101);
    while(cin >> n){
        int t = upper_bound(all(prime),n) - prime.begin();
        cout << t << endl;
    }
}

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

using namespace std;

int sosuu(int n) {
    vector< bool > prime(n + 1);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i <= n; i++) {
        prime[i] = true;
    }

    for (int j = 2; j * j <= n; j++) {
        if (prime[j] == true) {
            for (int i = j; i <= n; i++) {
                if (i % j == 0 && i != j) {
                    prime[i] = false;
                }
            }
        }
    }
    int count = 0;
    for (int i = 0; i <= n; i++) {
        if (prime[i] == true) {
            // cout << i << " ";
            count++;
        }
    }
    // cout << endl;
    return count;
}

int main() {
    int a;
    while (!cin.eof()) {
        cin >> a;
        if (std::cin.fail()) break;
        cout << sosuu(a) << endl;
    }

    return 0;
}