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<iostream>
#include<stdio.h>

using namespace std;

int ans = 0;

void Prime_number(int n){
	int i;
	int prime_num;

	for(i = 2; ; i++){
		if(n % i == 0 && n != i){
			break;
		}else if(n == i){
			ans++;
			break;
		}
	}

	if(n != 2){
		Prime_number(n-1);
	}
}

int main(){
	int n;

	while(cin >> n){
		Prime_number(n);
		cout << ans << endl;
		ans = 0;
	}

}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std; 

int list[1000000]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757,
 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	while(scanf("%ld",&hi)!= EOF)
	{
	lo=2;
	hasil=0;
	a=0;
	while(lo<=hi)
 	{
 		if(lo<list[179])
 		{
 			if(lo==list[a])
 			{
 				//printf("%ld\n",list[a]);
 				hasil++;
 				lo++;
 			}
 			else if(lo<list[a])
 			{
 				lo=list[a];
 			}
 			else if(lo>list[a])
 			{
 				a++; 
 			}
 		}
 		else 
 		{
 			if (Prima(lo)) 
 			{
 				//printf("%ld\n",lo);
 				hasil++;
 				lo++;
 			}
 			else
 			{
 				lo++; 
 			}
 		}
 	}
	printf("%d\n",hasil);
	}
	return 0; 
}

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

int main() {
	
	int n;
	int count;
	int prime[999999];
	int max=0;
	
	
	while( cin >> n ){
		if(n > max){
		
			count = 1;
			prime[0] = 2;
			for(int i=3;i<=n;i+=2){
				int isPrime = true;
			
				for(int j=0;j<count;++j){
					if(i%prime[j] == 0){isPrime = false;break;}
				}
				if(isPrime){
					prime[count] = i;
					count++;
				}
			}
			max = n;
		}else{
			count = 0;
			for(int i=0;i<999999;++i){
				if(prime[i] > n)break;
				count++;
			}
		}
		cout << count << endl;
		
	}
	return 0;
}

C++: #include <cstdio>
const int N = 1000000;
int p[N],int pN[N];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)prime[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i] = c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

C++: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n;
	int count = 1;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
	}
	else if (n == 2) {
		cout << 1 << endl;
	}
	else {
		for (int t = 3; t <= n - 1; t += 2) {
			FOR(i, 1, t - 1) {
				if (t%i == 0) {
					break;
				}
				if (i == t - 1) {
					count++;
					break;
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

C++: 
//  test.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    long int j,s[1000000]={0},d=1,i,n,k;
    
    s[0]=s[1]=1;
    
    for(i=2;i<1000000;i++){
        if(s[i]==0){
            
            for(j=2;j*j<=i;j+=2){
                if(i%j==0)
                    break;
                if(j==2)
                    j=1;
            }
            
            
            if(j*j>i){
                d++;
                printf("%ld\n",i);
                if(i<1000){
                    for(k=2;k*i<1000000;k++){
                        s[k*i]=-1;
                    }
                }
            }
        }
        s[i] = d;
    }
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]-1);
    }
    
    
    return 0;
}

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

int f[1000001];
int main(){
    fill_n(f,f+1000001,1);
    f[0]=f[1]=0;
    
    for(int i=2;i<1000001;i++){
        f[i]+=f[i-1];
        if(!f[i])continue;
        for(int j=i+i;j<1000001;j+=i)f[j]=0;
    }
    
    int N;
    
    while(scanf("%d",&N),&N){
        printf("%d\n",f[N]);
    }
    
    return 0;
    
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	int *prime = new int[n];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

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

using namespace std;

bool N[999999];

int FindPrime(int n) {
  int ans = 0;
  for(int i = 1; i <= sqrt(n); i++) {
    if(N[i - 1]) {
      for(int j = 2; j <= n / i; j++) {
        N[i * j - 1] = false;
      }
    }
  }

  for(int i = 0; i < n; i++) {
    if(N[i]) {
      ans++;
    }
  }

  return ans;
}

int main() {
  int n;
  while(cin >> n) {
    for(int i = 1; i < n; i++) {
      N[i] = true;
    }

    int ans = FindPrime(n);

    cout << ans << endl;
  }

  return 0;
}

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


bool isPrime(int I)
{
	int b = sqrt (I*1.0) + 1;
	for(int i = 2; i < b; i ++){
		if(I % i == 0)
			return false;
	}
	return true;
}
void printPrime(int N)
{
	int total = 0;
	for(int i = 2; i <= N; i ++)
	{		
		if(isPrime(i) == true){
			total ++;
		}
	}
	cout<<total<<endl;
}


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

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

int main() {
	
	int n;
	int count;
	int *prime;
	
	
	while( cin >> n ){
		prime = new int[n];
		count = 1;
		
		prime[0] = 2;
		
		for(int i=3;i<=n;i+=2){
			int isPrime = true;
			
			for(int j=0;j<count;++j){
				if(i%prime[j] == 0){
					isPrime = false;
					break;
				}
			}
			
			if(isPrime){
				prime[count] = i;
				count++;
			}
		}
		
		cout << count << endl;
		
		delete[] prime;
	}
	
	return 0;
}