Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

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

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

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

int pri[1000000]={0};


int main(){
	
	pri[0]=pri[1]=1;
	for(int i=2;i*i<=999999;i++){
		for(int j=i*2;pri[i]==0&&j<=999999;j+=i){
			pri[j]=1;
		}
	}
	
	int n;
	while(cin>>n){
		int tmp=0;
		for(int i=0;i<=n;i++){
			if(pri[i]==0)tmp++;
		}
		cout<<tmp<<endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int isPrime(int x){
  int i;

  if(x == 0 || x == 1) return 0;

  for(i=2;i*i<=x;i++){
    if(x % i == 0){
      return 0;
    }
  }
  return 1;
}

int main(void){
  int i,n;
  int res;

  while(scanf("%d",&n) != EOF){
    res = 0;
    for(i=2;i<=n;i++){
      if(isPrime(i)){
        res++;
      }
    }
    printf("%d\n",res);
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
  int n,prime[1000000],ans[1000000];


  for(int i=0;i<1000000;i++)prime[i]=ans[i]=0;
  prime[0]=prime[1]=1;

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

  while(cin >> n)
    cout << ans[n] << endl;
  
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  long long int a[1000000]={0};
  a[1]=1;
  for(int i=2;i<sqrt(1000000);i++){
    for(int j=2;j<sqrt(1000000);j++){     
      a[i*j]=1;
    }
  }
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    cont=0;
    for(int i=1;i<=n;i++){
      if(a[i]==0)cont++;
    }
    cout<<cont<<endl;
  }
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    map[0]=0;
    map[1]=0;
    sieve(2);
    sieve(3);
    sieve(5);
    for(int i=7;i<1000;i+=6)
    {
        sieve(i);
        sieve(i+4);
    }

    while(1)
    {
        int n;
        int num=scanf("%d",&n);
        if(num != 1)
            break;
        printf("%d\n",count(map.begin(),map.begin()+n+1,1));
    }
    return 0;
}

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


vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main()
{
	int n;
	while(cin>>n){
		vector<int> V=sieve_of_eratosthenes(n+1);
		V.erase(remove(V.begin(),V.end(),0),V.end());
		cout<<V.size()<<endl;
	}
	return 0;
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;
typedef long long int ll;

int main(){
    vector<int> era(10000000,0);
    for (int i=1; i<era.size(); i++) {
        era[i]=1;
    }
    for (int i=2; i<era.size(); i++) {
        if (era[i]!=0) {
            int q = i + i;
            while (q<era.size()) {
                era[q]=0;
                q += i;
            }
        }
    }
    int n;
    while (cin >> n) {
        int ans=-1;
        for (int i=1; i<=n; i++) {
            if (era[i]) {
                ans++;
            }
        }
        cout << ans <<endl;
    }
}

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

C++: 
#include<stdio.h>
#include<string.h>
#define range 999999
int total_added = 4;
struct primes{
	 int  key;
	 int  counts;
};
primes p[range];
bool is_prime(int key)
{
	int i;
	for (i = 2; i <= sqrt(key); i++)
	{
		if (key%i == 0)return false;
	}
	return true;
}
void init()
{
	p[0].key = 2;
	p[0].counts = 1;
	p[1].key = 3;
	p[1].counts = 2;
	p[2].key = 5;
	p[2].counts = 3;
	p[3].key = 7;
	p[3].counts = 4;
	int i;
	for (i = 8; i <= range; i++)
	{
		if (i % 2 != 0&&i%3!=0&&i%5!=0)
		{
			if (is_prime(i))
			{
				p[total_added].key = i;
				p[total_added].counts = p[total_added - 1].counts + 1;
				total_added++;
			}
		}
	}
}
int counting_result(int key)
{
	for (int i =total_added-1; i>=0; i--)
	{
		if (key >= p[i].key)
			return p[i].counts;
	}
	return 0;
}

int main()
{
	init();
	int i=0, n;
	while (i<30)
	{
		scanf("%d", &n);
		printf("%d\n",counting_result(n));
		i++;
	}

}

C++: #include<iostream>
#define N 1000001
using namespace std;
int main(){
  int n;
  int p[N]={0};
  for(int i=3;i<=N;i+=2) p[i] = 1;
  p[2] = 1;
  for(int i=3;i<=1000;i+=2){
    if(p[i]==1){
      for(int j=2*i;j<=N;j+=i) p[j] = 0;
    }
  }
  while(cin>>n){
    int count = 0;
    if(2<=n) count++;
    for(int i=3;i<=n;i+=2){
      if(p[i]) count++;
    }
    cout << count << endl;
  }
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	while (cin >> n){
		int cnt=0;
		for (int i=2; i<=n; ++i){
			bool op=false;
			for (int j=2; j<=sqrt(i); ++j){
				if (i%j == 0){
					op = true;
					break;
				}
			}
			if (op == false) ++cnt;
		}
		cout << cnt << '\n';
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (n == 2) {
            cout << 1 << endl;
            continue;
        }

        int ans = 1;
        for (int i = 3; i <= n; i += 2) {
            bool flag = true;
            
            if (!(i % 2))
                continue;
            for (int j = 3; j * j <= i; j += 2) {
                if (!(i % j)) {
                    flag = false;
                    break;
                }
            }
            if (flag)
                ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

using namespace std;

vector<bool> prime(1000010, 1);
int n;

void precalc()
{
    prime[0] = 0; prime[1] = 0; prime[2] = 1;
    for( int i = 2; i * i <= 999999; i++ ){
        if( prime[i] ){
            for( int j = 1; ( j + 1 ) * i <= 999999; j++ ){
                prime[i * ( j + 1 )] = 0;
            }
        }
    }

}

signed main(){
    precalc();
    while( scanf( "%d", &n ) != EOF )
    {
        int ret = 0;
        for( int i = 0; i <= n; i++ )
        {
            if( prime[i] )
            {
                ret++;
            }
        }
        printf( "%d\n", ret );
    }
    return 0;
}