Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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


using namespace std;



bool isPrime(int num) {
	int root = (int)sqrt(num);
	for (int i = 3; i <= root; i += 2) {
		if (num % i == 0)return false;
	}
	return true;
}

int main() {

	int num;
	while (cin >> num) {
		int count = 0;
		if (num >= 2)count++;

		for (int i = 3; i <= num; i += 2) {
			if (isPrime(i))count++;
		}
		printf("%d\n",count);
	}


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

C++: /*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/
/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	
	bool *prime;
	int num;
	int n;
	
	/*****処理部*****/
	while(1){
		cin >> n;
		prime = new bool [n+1];
		for(int i=0;i<n+1;i++){
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		for(int i=0;i<n+1;i++){
			if(prime[i]){
				for(int j=2*i;j<n+1;j+=i){
					prime[j] = false;
				}
			}
		}
		num = 0;
		for(int i=0;i<n+1;i++){
			if(prime[i])	num++;
		}
		cout << num << endl;
		delete prime;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int n,ans=0;
    while(scanf("%d",&n)!=-1){
        vector<bool> tab(n+1,true);
        int upto=sqrt(n);
        for(int i=2;i<=upto;i++){
            if(tab[i]){
                for(int j=i*2;j<=n;j+=i){
                    tab[j]=false;
                }
            }
        }
        for(int i=2;i<=n;i++){
            if(tab[i]) ans++;
        }
        printf("%d\n",ans);
    }
}

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

using namespace std;

int prime(int n);

int main(){
  vector<int> inp;
  int num,pri;					
  int i=0;

  while(cin>>num){
    if(num <= 1)inp.push_back(0);
    else{
      pri = prime(num);
      inp.push_back(pri);
    }
    i++;
  }
  int j = 0;
  while(j < i){
    cout<<inp[j]<<endl;
    j++;
  }
}

int prime(int num){
  int count=0;
  bool judge=0;
  for(int i = 2; i <= num; i++){
    judge =1;
    for(int j= 2; j < i; j++){
      if(i%j == 0)judge =0;
    }
    if(judge==1)count = count +1; 
  }
  return count;
}

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

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

int main(){
	long long int prime[999999];
	long long int ptr=0;
	
	prime[ptr++]=2;
	prime[ptr++]=3;

	for(int no = 5 ; no <=  999999 ; no += 2){
		int flag = 0;
		for (int i = 1; prime[i] * prime[i] <= no ; i++){
			if(no % prime[i] == 0){
				flag=1;
				break;
			}
		}
		if(!flag)
			prime[ptr++] = no;
	}
	
	
	int n,co=0;
	while(cin>>n){
		co=0;
		for(int i=0; prime[i] <= n ;i++){
			co++;
		}
		cout<<co <<endl;
	}
}

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

using namespace std;

constexpr int MAX = 1000000;

int main()
{
    vector<bool> prime_list(MAX, true);
    prime_list.at(0) = false;
    prime_list.at(1) = false;
    for(int i = 2; i * i < MAX; ++i)
    {
        if(!prime_list.at(i))
            continue;
        for(int j = 2; i * j < MAX; ++j)
            prime_list.at(i * j) = false;
    }

    int num;
    int count;
    while(cin >> num)
    {
        count = 0;
        for(int i = 2; i < num; ++i)
        {
            if(prime_list.at(i))
                count++;
        }
        cout << count << endl;
    }
}

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

using namespace std;

const int M = 1e7+10;
bool isPrime[M];

void sieve(){
    for(int i=2;i<M;i++) isPrime[i] = true;
    for(int i=2;i*i<M;i++){
        if(!isPrime[i]) continue;
        for(int j=2*i;j<M;j+=i){
            isPrime[j] = false;
        }
    }
}

int main(){
    sieve();
    int n;
    while(cin >> n){
        int c = 0;
        for(int i=0;i<=n;i++){
            if(isPrime[i]) c++;
        }
        cout << c << endl;
    }
}

C++: #include<iostream>
#define MAX 1000000

using namespace std;

bool prime[MAX+1];
int T[MAX];

void eratos( int n ){
    for ( int i = 0; i < n; i++ ) prime[i] = false;
    for ( int i = 3; i <= n; i += 2 ) prime[i] = true;
    prime[2] = true;
    for ( int i = 3, limit = (int)sqrt(n); i <= limit; i += 2 ) {
	if ( !prime[i] ) continue;
	for ( int j = i * i, k = i * 2; j <= n; j += k ) prime[j] = false;
    }
}

void initialize(){
    eratos( MAX );
    for ( int i = 0; i < MAX; i++ ){
	T[i] = T[i - 1];
	if ( prime[i] ) T[i]++;
    }
}

main(){
    initialize();
    int n;
    while ( cin >> n ) cout << T[n] << endl;
}

C++: #include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
#define	MAXPRIME	999999
using namespace std;

typedef unsigned int uint;

void setPrimeFlag(bool *primeFlag, uint maxPrime) {
	uint sq = (uint)sqrt((double)maxPrime) + 1;
	for (uint i = 2; i <= maxPrime; ++i) { primeFlag[i] = true; }
	primeFlag[0] = primeFlag[1] = false;
	for (uint i = 2; i <= sq; ++i) {
		if (primeFlag[i]) {
			for (uint j = i + i; j <= maxPrime; j += i) {
				primeFlag[j] = false;
			}
		}
	}
}

template <class ARR> void setPrimeArray(ARR &primeArray, uint maxPrime) {
	bool *primeFlag = new bool[maxPrime + 1];
	setPrimeFlag(primeFlag, maxPrime);

	primeArray.clear();
	for (uint i = 2; i <= maxPrime; ++i) {
		if (primeFlag[i]) {
			primeArray.push_back(i);
		}
	}
	delete [] primeFlag;
}

int main() {
	vector<uint> primeArray;
	setPrimeArray<vector<uint>>(primeArray, MAXPRIME + 1);

	for (;;) {
		uint n, num;
		cin >> n;
		if (cin.eof()) { break; }

		for (num = 0; num < primeArray.size() && primeArray[num] <= n; ++num);

		cout << num << endl;
	}

	return 0;
}

C++: #include<cstdio>

#define MAX 1200000
using namespace std;
int prim[1200100];
int prima[1200100];
int main() {
    int n, i, x = 0;
    for (i = 2; i <= MAX; i++) {
        prim[i] = i;
    }
    for (i = 2; i <= MAX; i++) {
        if (prim[i] != 0) {
                  prima[x] = prim[i];
                  x+= 1;
                  int j = i;
                  while ( j <= MAX) {
                        prim[j] = 0;
                        j+= i;
                  }
        }
    }
    while (scanf("%d", &n) != EOF) {
          int a = 0;
          while ( prima[a] <= n) {
                a++;
          }
          printf("%d\n", a);
    }
    return 0;
}

C++: #include<stdio.h> int main(void){ int a,b,r,ans,a1,b1; double c; while(scanf("%d %d",&a,&b)!=EOF){ a1=a,b1=b; while(1){ r=a%b; if(r==0){ ans=b; break; }else{ a=b; b=r; } } c=(double)(a1)*(double)(b1)/(double)(ans); printf("%d %.0f\n",ans,c); } return 0; }