Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

bool prime[10000005];
int p[700000]; 
int main()
{	
	int k=0;
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=999999;++i)
	{
		if(prime[i]==0)
		{	
			p[k++]=i;		
			for(int j=i+i;j<=999999;j+=i)	
			{
				prime[j]=1;
			}
		}
	}
	int n;
	while(cin>>n){
		//for(int i=0;i<10;++i)cout<<p[i]<<endl;
		int ans = lower_bound(p,p+k,n)-p;
		//cout<<p[ans]<<endl;
		if(p[ans]==n)ans++;
		cout<<ans<<endl;
	} 

}

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

int Era(int N) {
	int prime_num = 0;
	int* array = new int[N + 1];
	for (int i = 2; i < N + 1; i++) {
		array[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (array[i]) {
			for (int j = 0; i*(j + 2) <= N; j++) {
				array[i*(j + 2)] = 0;
			}
		}
	}
	for (int i = 2; i < N + 1; i++) {
		if (array[i])prime_num++;
	}
	return prime_num;
}

int main() {
	int num;
	while (cin >> num) {
		cout << Era(num) << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int i,j,number,count=0,hantei=0;
	while(cin>>number){
		count=0;
		for(i=2;i<number;i++){
			hantei=0;
			for(j=0;j<i/2;j++){
				if(i%j==0){
					hantei++;
				}
			}
			if(hantei==0){
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  const int max = 1000000;
  vector<int> result;
  bool nums[max];
  for (int i = 2; i < max; i++)
    nums[i] = true;
  for (int i = 2; i < max; i++) {
    if (!nums[i])
      continue;
    else if (i * i > max)
      break;
    for (int j = i+1; j < max; j++) {
      if (!nums[j])
        continue;
      else if (j % i == 0)
        nums[j] = false;
    }
  }

  while (cin >> n) {
    int piyo = 0;
    for (int i = 2; i <= n; i++)
      if (nums[i])
        piyo++;
    result.push_back(piyo);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

C++: #include<iostream>
int main(){
	int n;
	while(1){
		std::cin>>n;
		if(std::cin.eof())break;
		int m=0,l=0;
		for(int i=2;i<=n;i++){
			for(int j=2;j<=i/2;j++){
				if(i%j==0)m++;
			}
			if(m==0)l++;
			m=0;
		}
		std::cout<<l<<std::endl;
	}
	return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	int a[1000000];
	a[0]=1;
	a[1]=1;
	for(int i=2;i<1000000;){
		if(a[i]==0){
			for(int j=i;j<1000000;j+=i){
				a[j]=1;
			}
		}
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<b;i++){
			if(a[i]>b)break;
			else {
				if(a[i]==1) c++;
			}
		}
		cout<<c<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
 
using namespace std;
 
int main(){
    int n;
    int nums[100000] = {0};
    while(cin >> n){
        int count = 0;
        int qf = 0;
        int qe = 0;
        for(int i = 2; i <= n; i++){
            bool f = false;
            for(int qe = 0; qe < qf; qe++ ){
                if(i < nums[qe] * nums[qe]) break;
                if(i % nums[qe] == 0) {
                    f = true;
                    break;
                }
            }
            if(!f) { count++; nums[qf] = i; qf++; }
        }
        cout << count << 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;
			}
		}
	}

	vector <int> answers;
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		int c = 0;
		if ( n == 2 )
			c = 1;
		else if( n < 2 )
			c = 0;
		else
		{
			c = 1;
			for ( int i = 3; i <= n; i += 2 )
			{
				if ( primes[i] )
					c++;
			}
		}

		answers.push_back( c );
	}

	for ( vector <int>::iterator it = answers.begin(); it != answers.end(); it++ )
	{
		cout << *it << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

#define MAX_PRIME 1000000

vector<int> primes;

// sieve of Erastosthenes
inline void prime_list(){
  vector<bool> isPrime(MAX_PRIME+1, true);
  const int sz = MAX_PRIME;
  isPrime[0]=isPrime[1]=false;
  for(int i=4;i<=sz;i+=2) isPrime[i]=false;
  primes.pb(2);
  for(int i=3; i<=sz; i+=2){
    if(isPrime[i]){
      primes.pb(i);
      for(long j=(long)i*i; j<=sz; j+=i) isPrime[j]=false;
    }
  }
}

int main(){
  prime_list();
  int d;
  while(cin>>d){
    cout << upper_bound(all(primes), d) - primes.begin() << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main() {
  long n;
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    int x = 1;
    if (n == 2) {
      cout << x << endl;
      continue;
    }
    x++;
    for (int i = 3; i <= n; i += 2)
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) break;
        if (j + 1 > sqrt(i)) x++;
      }
    cout << x << endl;
  }
}

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

int main() {
int b[1000000];
for (int k=0;k<1000001;k++){
	b[k]=0;
}
b[2]=1;
b[3]=1;
b[4]=0;
b[5]=1;
b[6]=0;
b[7]=1;

for (int p=10;p<1000001;p++){
int i,a=0 ;
	i=3;
	while(i<sqrt(p)){
		if(p%i==0){
			break;
	}i=i+2;
	}
	if (i>=sqrt(p)){
		a=1;
	}
	b[p]=a;
}
int c[1000000];
for (int l=0;l<1000001;l++){
	c[l+1]=c[l]+b[l+1];
}
int r;
while(cin>>r){
	cout<<c[r]<<endl;
}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp = 0;
	
	while(cin>>n)
	{
		vector<int> isPrime(n,1);
		
		isPrime[0] = isPrime[1] = 0;
		
		for(;;){
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i < n; i++){
				isPrime[i*head] = 0;
			}
			
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin < head*head){
				break;
			}
			temp = head;
		}
		int cont = 0;
		
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
			}
		}
		printf("%d\n",cont);
	}
}