Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

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

C++: #include<iostream>
#include<vector>
using namespace std;
#define SIZE 1000000
int main(){
	vector<bool>bo(SIZE,false);
	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			for(int j=i*2;j<SIZE;j+=i){
				bo[j]=true;
			}
		}
	}
	vector<int>ans(SIZE);

	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			ans[i]=ans[i-1]+1;
		}
		else {
			ans[i]=ans[i-1];
		}
	}
	int n;
	while(cin>>n){
		cout<<ans[n]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
#define MAX 1000000
#define LMT 1000
int sieve();
int calculation();
unsigned flag[MAX>>6];

int primes[5761455];
#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))
int main()
{
    sieve();
    return 0;
}

int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    calculation();
    return 0;
}

int calculation()
{
    unsigned int i;
    int k = 1;
    primes[0] = 2;
    for( i=3; i<MAX; i+=2)
    {
        if(ifc(i)==0)
            primes[k++] = i;
    }
    int input;
    int count;
    while(scanf("%d",&input)==1)
    {
        count=0;
        for(i=0; primes[i]<=input; i++)
            count++;
        printf("%d\n",count);
    }
    return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int count;
	c[0]=c[1]=0;
	for(i=2;i<100000;i++){
		c[i]=1;
	}

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

		count=0;

		
		for(i=2;i<=n;i++){
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0){
						c[j]=0;
					}
				}
				count++;
			}
		}

		printf("%d",count);


	}





	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int n;
	while (std::cin >> n)
	{
		std::vector<bool> v(n + 1 ,false);
		int c = 0;
		v[0] = true, v[1] = true;
		for (int i = 2; i * i <= n ; ++i) {
			if (!v[i]) {
				for (int j = i * i; j <= n; j += i) {
					v[j] = true;
					++c;
				}
			}
		}

		std::cout << n-c-1 << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e8);
bool p[MAX];
short num[MAX];
void isPrime(){
  rep(i,MAX)p[i] = true;
  p[0] = p[1] = false;
  num[0] = num[1] = 0;
  loop(i,2,MAX){
    num[i] = num[i-1] + p[i];
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i){
	p[j] = false;
      }
    }
  }
}

int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<num[n]<<endl;
  
  return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

void Sieve(int n)
{
	bool prime[n+1];
	int c=0;
	memset(prime, true, sizeof(prime));

	for (int p=2; p<=n; p++)
	{
		if (prime[p] == true)
		{
			for (int i=p*2; i<=n; i += p)
				prime[i] = false;
		}
	}
	for (int p=2; p<=n; p++)
	if (prime[p])
		c++;
		cout<<c<<endl;
}

int main()
{
	int n;
	while(cin>>n){
        Sieve(n);
	}

	return 0;
}

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

int main() {
	int n;

	while (std::cin >> n) {
		std::vector<int> nums;
		++n;
		for (int i = 0; i < n; ++i) {
			nums.push_back(i);
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) < 2) continue;
			for (int j = nums.at(i) * 2; j < n; j += nums.at(i)) {
				nums.at(j) = 0;
			}
		}
		std::cout << std::count_if(nums.begin(), nums.end(), [](auto const& n) { return n > 1; }) << std::endl;
	}
	return 0;
}

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

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        for(j=past+1; j<=a; j++){
          if(j%i==0) chk[j]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

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

using namespace std;

int main()
{
	int n;
	int count;
	while (cin >> n, !cin.eof())
	{
		count = 0;
		vector<int> p(n + 1, 1);
		p[1] = 0;
		for (int i = 2; i * i <= n; i++)
		{
			if (p[i] == 0) continue;
			for (int j = 2; i * j <= n; j++)
			{
				p[i * j] = 0;
			}
		}
		for (int i = 1; i <= n; i++)
		{
			count += p[i];
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int phi[1000000];
bool vis[1000000];
int p[1000000];
int sieve(int n) {
		int i, j,cnt=0;
		phi[1] = 1;
		for (i = 2; i < n; ++i) {
			if (!vis[i]) {
				p[cnt++] = i;
				phi[i] = i - 1;
			}
			for (j = 0; j < cnt && i * p[j] < n; ++j) {
				vis[i * p[j]] = true;
				if (i % p[j]) phi[i * p[j]] = phi[i] * phi[p[j]];
				else {
					phi[i * p[j]] = phi[i] * p[j];
					break;
				}
			}
		}
		return cnt;
	}
	
	


int main()
{
	int n;
	while (scanf("%d",&n)) {
		printf("%d\n", sieve(n));
	}
			
	

    return 0;
}

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

#define MAX_NUM (1000000)

static int getPrimeNum(int maxVal);

int main(void)
{
  int n;
  
  while (std::cin >> n) {
    std::cout << getPrimeNum(n) << std::endl;
  }
  
  return 0;
}

static int getPrimeNum(int maxVal)
{
  static int searchList[MAX_NUM] = {0};
  static int primeList[MAX_NUM] = {0};
  
  memset(searchList, 0, sizeof(int) * MAX_NUM);
  memset(primeList, 0, sizeof(int) * MAX_NUM);
  
  double sqMaxVal = sqrt((double)maxVal) + 1;
  
  for (int i = 2; i <= sqMaxVal; i++) {
    if (searchList[i] == 0) {
      searchList[i] = 1;
      primeList[i] = 1;
      for (int j = i + 1; j <= maxVal; j++) {
        if (j % i == 0) {
          searchList[j] = 1;
        }
      }
    }
  }
  
  for (int i = 2; i <= maxVal; i++) {
    if (searchList[i] == 0) {
      primeList[i] = 1;
    }
  }
  
  int count = 0;
  for (int i = 2; i <= maxVal; i++) {
    if (primeList[i] == 1) {
      count++;
    }
  }
  
  return count;
}

C++: #include <iostream>
using namespace std;
#define N 1000000
int a[N];
int main(){
	int i,j;
	a[0]=0;a[1]=0;
	for(i=2;i<N;i++){
		a[i]=1;
	}
	for(i=2;i<N/2+1;i++){
		j=2;
		while(i*j<N){
			a[i*j]=0;
			j+=1;
		}
	}
	int n;
	while(cin>>n){
		j=0;
		for(i=2;i<=n;i++){
			j+=a[i];
		}
		cout<<j<<endl;
	}
}