Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		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:
		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>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 999999;
bool p[MAX_N+1];
int sum[MAX_N+1];

void make_prime (void )
{
	fill (p, p+MAX_N+1, true );
	memset (sum, 0, sizeof (sum ) );
	p[0] = false;
	p[1] = false;
	for (int i = 2; i <= MAX_N; i++ ){
		if (p[i] ){
			for (int j = 2*i; j <= MAX_N; j += i ){
				p[j] = false;
			} // end for
		} // end if
	} // end for

	for (int i = 1; i <= MAX_N; i++ ){
		sum[i] = sum[i-1] + (p[i] ? 1 : 0 );
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.PN", "r", stdin );
	make_prime ();

	string str = "";
	while (getline (cin, str ) ){
		stringstream ss (str );
		int n;
		ss >> n;
		printf ("%d\n", sum[n] );
	} // end while

	return 0;
}

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

bool p[1000000];

int main(){
	int c,n;
	while(cin >> n){
		c = 0;
		for(int i = 2; i <= sqrt(n); i++){
			for(int j = 2; i * j <= n; j++){
				p[i*j] = true;
			}
			
		}
		for(int i = 2; i <= n; i++){
			if(p[i] == 0){
				c++;
				
			}
		}
		cout << c << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <array>
&#160;
int main() {
&#160;&#160;&#160;&#160;std::array<bool, 1000000> is_prime_table = { false, false, true };
&#160;&#160;&#160;&#160;for( int i=3; i<=is_prime_table.size(); i+=2 ) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;is_prime_table[i] = [&i]() -> bool
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for( int j=3; j*j<=i; j+=2 )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ( i % j == 0 )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return false;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return true;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}();
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;int num = 0;
&#160;&#160;&#160;&#160;while( std::cin >> num ) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;int result = num > 1 ? 1 : 0;&#160;&#160;&#160; // 2
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for( int i=3; i<=num; i+=2 )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ( is_prime_table[i] )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;++result;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;std::cout << result << std::endl;
&#160;&#160;&#160;&#160;}
}

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

using namespace std;

long* primes(long high)
{
  long* p = new long[high];
  for (int i = 0; i < high; i++) {
    p[i] = 0;
  }

  long max = ceil(sqrt(high));
  for (int i = 2; i <= max; i++) {
    if (p[i - 1] == -1) continue;

    int count = 2;
    while (i * count <= high) {
      p[i * count - 1] = -1;
      count++;
    }
  }

  for (int i = 1; i < high; i++) {
    if (p[i] == -1) {
      p[i] = p[i - 1];
    } else {
      p[i] = p[i - 1] + 1;
    }
  }
  
  return p;
}

int main(int argc, char const* argv[])
{
  long* p = primes(999999);
  long n;

  while (cin >> n) {
    cout << p[n - 1] << endl;
  }
  return 0;
}

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

C++: #include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main()
{int n;
 while(scanf("%d",&n))
 {int sum=1;
  int i;
  for(int m=3;m<=n;m++)
  {if(m%2==0)continue;
	  int k=int (sqrt(double(m)));
	  i=2;
   while(m%i&&i<=k)
	   i++;
   if(i>k)sum++;
  }
  printf("%d\n",sum);
 }
}

C++: #include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		n += 1;
		bool *p = new bool[n];
		fill(p, p + n, true);
		p[0] = p[1] = false;
		for (int i = 2; i * i < n; i++)
			if (p[i] == true)
				for (int j = i * i; j < n; j += i)
					p[j] = false;
		for (int i = 0; i < n; i++)
			if (p[i] == true)
				ans++;
		cout << ans << endl;
		delete[] p;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> array;
	int n;
	bool f;
	cin >> n;
	for(int i=2;i<=n;i++){
		f=true;
		for(int j=0;j<array.size();j++)
		if(!(i%array[j])){
		f=false;
		continue;
	}
		if(f==true)array.push_back(i);
	}
	cout << array.size();
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,sum;
    int b[999999];
    b[0]=0;
    for(int i=1;i<999999;i++){
        b[i]=prime(i+1);
    }
    while ( cin >> a){
        sum =0;
        for (int i=1;i<a;i++){
            sum +=b[i];
        }
        cout << sum << endl;
    }
}
int prime(int x){
    if(x==1)
        return 0;
    if(x==2 || x==3 || x==5 || x==7)
        return 1;
    if(x%2==0 || x%3==0)
        return 0;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 0;
    }
    return 1;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int prime[1000000];
bool is_prime[100001];

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

int main(){
  int n;
  while(scanf("%d",&n)!=EOF)
    cout<<sieve(n)<<endl;
  return 0;
}

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

int prime[1000000] = {1};

int main()
{
  int n;
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 1000000; i++){
    if (prime[i] == 1){
      for (int j = 2 * i; j < 1000000; j += i){
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 1000000; i++){
    prime[i + i] += prime[i];
  }
  while (cin >> n){
    cout << prime[n];
  }

  return 0;
}

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

int main(){
  int n;

  while(cin >> n){
    int cnt = 0;
    for(int i = 1; i <= n; i++){

      if(i % 2 == 0|| i % 3 == 0 || i % 5 == 0) continue;

      int yakusuu = 0;

      for(int j = 1; i <= i; j++){
        if(i % j == 0) yakusuu++;
      }

      if(yakusuu==2) cnt++;

    }
    cout << cnt + 3 - 1 << endl;
  }
  return 0;
}