Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		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
}

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

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

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

bool isprime(int n){
	if(n==2 || n==3)
		return true;
	else{
		for(int i=2; i<=sqrt(n); i++){
			if(n%i==0)
				return false;
		}
		return true;
	}
}

int main(){
	int n;
	while(cin >> n){
		int cnt=0;
		for(int i=2; i<=n; i++){
			bool flag;
			flag=isprime(i);
			if(flag==true)
				cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];
int sum[MAX_V+2];
void init(){
    int i, k, v;
    for(i=2; i<=MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

void accumulate(){
   for(int i=1; i<MAX_V+2; i++){
        if(i==1){
            sum[i]=0;
        }else{
            sum[i]=sum[i-1]+prime[i];
        }
    }
}


int main(){
    init();
    accumulate();
    int num;
    while(scanf("%d", &num) != EOF){
        printf("%d\n", sum[num]);
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
bool isPrime[1000000];
void calcPrime(){
  fill(isPrime, isPrime+1000000, true);
  isPrime[0] = isPrime[1] = false;

  for(int i = 4; i < 1000000; i+=2){
    isPrime[i] = false;
  }
  
  for(int i = 3; i*i < 1000000; i+=2){
    if(isPrime[i] == false)continue;
    for(int j = i+i; j < 1000000; j+=i){
      isPrime[j] = false;
    }
  }
}
int main(){
  calcPrime();
  int n;
  while(cin >> n){
    int cnt = 0;
    for(int i = 2; i <= n; i++){
      if(isPrime[i])cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

int main(){
  bool p[1000000];
  int num[1000000];
  int c,n;

  for(int i=0;i<1000000;i+=2)p[i] = false;
  for(int i=1;i<1000000;i+=2)p[i] = true;
  p[1] = false;
  p[2] = true;

  c = 3;
  while(c < 1000){
    for(int i=3*c;i<1000000;i+=2*c)p[i] = false;
    do{c+=2;}while(!p[c]);
  }

  c = 0;
  for(int i=0;i<1000000;i++){
    if(p[i])c++;
    num[i] = c;
  }

  while(cin >> n)cout << num[n] << endl;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
struct PrimeNumbers {
    vector<bool> sieve;
    vector<int> prime;
    PrimeNumbers(int n) : sieve(n+1,true) {
        sieve[0] = sieve[1] = false;
        for(long long i=2; i<sieve.size(); i++){
            if(sieve[i]){
                prime.push_back((int)i);
                for(long long j=i*i; j<sieve.size(); j+=i) {
                    sieve[j] = false;
                }
            }
        }
    }
    int size(void) { return (int)prime.size(); }
    int & operator [] (int n) { return prime[n]; }
    bool operator == (int n) { return sieve[n]; }
    bool operator != (int n) { return sieve[n]; }
};

int main() {

    int t;
    while(cin >> t) {
        PrimeNumbers p(t);
        cout << p.size() << endl;
    }
    return 0;
}

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

int arr[N];

void Eratosthenes(){
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
	return;
}

int main(){
	int i,j=0,n,pn;
	while(cin>>n){
		pn=0;
		Eratosthenes();
		for(i=2 ; i<=n ; i++){
			if(arr[i]==1) pn++;
		}
		cout << pn << endl;
		
	}
	return 0;
}

C++: int main(){
int n;
while(cin >> n){
int a[n+1];
int b;
int c;
b=1;
while(b<n+1){
a[b]=0;
b=b+1;}
a[1]=1;
int d;
d=0;
b=2;
while(b<n+1){
if(a[b]==0){d=d+1; c=2; while(1){if(c*b>n){break;} a[c*b]=1; c=c+1;}}
b=b+1;}
cout << d;}

C++: #include<stdio.h>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    long int arr[999999];
    int p=0;
    int i,b,a;
    for(a=2;a<=999999;a++){

                b=0;
                for(i=2;i<=sqrt(a);i++){
                    if(a%i==0){
                    b=1;
                    break;
                    }
                }
                if(b==0){
                arr[p]=a;
                p++;
                }
            }
    int num,cot;
    while(scanf("%d",&num)!=EOF){
            cot=0;
            for(i=0;i<=999999;i++){
                if(arr[i]<=num)
                    cot++;
                else
                    break;
            }
            cout << cot << endl;
    }
    return 0;
}

C++: #include <iostream>

int main() {
    int n;
    while (std::cin >> n) {
        int primes = 0; // n以下の素数の数
        for (int i = 2; i <= n; i++) {
            bool flag = false; // はずれの目印
            for (int j = 2; j < i; j++)
                if (!(i % j)) {
                    flag = true;
                    break;
                }   
            if (!flag)
                 primes++;
        }
        std::cout << primes << std::endl;
     }   
}

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

using namespace std;

int main() {
  int n;
  
  while(!cin.eof()) {
    cin >> n;
    list<int> search_list(n-1);
    list<int> prime_number;
    while(n!=1) {
      search_list.push_front(n);
      n--;
    }
    while(!search_list.empty()) {
      int m = search_list.front();
      prime_number.push_back(m);
      search_list.pop_front();
      list<int>::iterator it = search_list.begin();
      while(it!=search_list.end()) {
	if((*it % m) == 0){
	  it = search_list.erase(it);
	  continue;
	}
	it++;
      }				   
    }
    cout << prime_number.size()-1 << endl;
    prime_number.erase();
    search_list.erase();
  }
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;


bool isPrime( int n ) {
	for( int i = 2; i * i <= n; i++ ) {
		if( n % i == 0 ) return false;
	}
	return true;
}


int main(void){


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

		int cnt = 0;
		for( int i = 2; i <= n; i++ )
			if( isPrime(i) )
				cnt ++;
		cout << cnt << endl;

	}

    return 0;
}

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

bool isPrime(int num) {
	if (num == 1)return false;
	if (num == 2)return true;

	for (int i = 2; i *i <= num; i++) {
		if (num % i == 0)return false;
	}
	return true;
}


int main() {

	int num;
	int count;
	while (cin >> num) {
		count = 0;
		for (int i = 1; i <= num; i++) {
			if (isPrime(i))count++;
		}
		printf("%d\n", count);

	}

	//system("pause");
	return 0;
}