Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

using namespace std;

int main() {

	int n,count;

	while (cin >> n) {
		
		//?´???°????????????????¨???¶?????????????????????????¢????
		bool *is_prime;
		is_prime = (bool *)malloc(n+1);
		if (is_prime == NULL) {
			cout << "malloc error" << endl;
			break;
		}

		//2????????§????????¶??°???????????????????????????
		//????????¨????´???°??§????????¨??????
		is_prime[2] = true;
		for (int i = 3; i <= n; i+=2) {
			is_prime[i] = true;
		}

		for (int i = 3; i <= sqrt(n); i+=2) {
			//?´???°???????????§????????£???????????????????????§??????
			if (is_prime[i] == true) {
				//????????°???????????§????????°????????£?????????
				for (int j = i+2; j <= n; j+=2) {
					//cout << "i=" << i << " j=" << j << " is_prime(i)=" << is_prime[i] << " is_prime(j)=" << is_prime[j] << endl;
					if (is_prime[j] == true) {
						if (j%i == 0) {
							//????????????????????????????´???°??§?????????
							is_prime[j] = false;
						}
					}
				}
			}
		}

		//?´???°??¨?¢????????????°????????°????????????
		count = 1;  //2?????¶??°??§???????´???°????????§????????\???????????????
		for (int i = 3; i <= n; i+=2) {
			if (is_prime[i] == true) {
				count++;
				//cout << " " << i;
			}
		}

		//??¨???
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool isprime(int& num)
{
    static int c;
    for(c=2; c < num; c++)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans = 0;
    int buff;
    while(cin >> buff);
    {
        for(int d =2; d <= buff; d++)
            if(isprime(d)) ans++;
        cout << ans << " ";
        ans  = 0;
    }
    cout << endl;
    return 0;
}

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

int main(){

	int n;

	while(std::cin>>n){

		int c2=1;	//2

		for(int i=3;i<=n;i+=2){

			int c=0;

			for(int j=3;j<=sqrt(i);j+=2){

				if(i%j==0){

					c++;
					break;

				}
			}

			if(c==0)c2++;
		}

		std::cout<<c2<<std::endl;

	}

}

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

long long gcd(long long a, long long b)
{
    return b?gcd(b,a%b):a;
}
long long m,n;
int main()
{
    while(~scanf("%lld%lld",&m,&n))
    {
        long long temp = gcd(m,n);
        printf("%lld %lld\n",temp,m*n/temp);
    }
    return 0;
}

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

void markMultiples(bool arr[], int a, int n)
{
    int i = 2, num;
    while ( (num = i*a) <= n )
    {
        arr[ num-1 ] = 1; 
        ++i;
    }
    
}
 

void prime_Number(int n)
{
    
    if (n >= 2)
    {
        bool arr[n];
        memset(arr, 0, sizeof(arr));
 
        for (int i=1; i<n; ++i)
        {
            if ( arr[i] == 0 )
            {
                cout<<i+1 <<endl;
                markMultiples(arr, i+1, n);
            }
        }
    }
}
 
int main()
{
    int n;
    cin>>n;
    prime_Number(n);
    
    return 0;
}

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

int main()
{
	int input;
	int i, j, k, cnt;
	bool fg;
	for(i = 0; i < 30; i++)
	{
		cin >> input;
		cnt = 0;

		for(k = 2; k <= input; k++)
		{
			fg = false;
			for(j = 2; j <= sqrt(k); j++)
			{
				if(k % j == 0)
				{
					fg = true;
					break;
				}
			}
			if(!fg) cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include <cstdio>
#include <cmath>
#define MAX_N 1000000

int main(){
    bool p[MAX_N+1];    // p[NUM] : NUM is Prime?
    int n;

    for(int i = 0; i <= MAX_N; i++) p[i] = true;

    for(int i = 1; i <= MAX_N; i++){
        if(i == 1) p[i] = false;
        else{
            if(p[i]){
                for(int j = 2; i * j <= MAX_N; j++){
                   p[i*j] = false;
                }
            }
        }
    }
 
    // for(int i = 0; i <= MAX_N; i++) if(p[i]) printf("%d\n",i);
    
    while(scanf("%d", &n) == 1){
        int count = 0;
        for(int i = 1; i <= n; i++){
            if(p[i])count++;
        }
        printf("%d\n", count);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

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

int main(){
int n;

while(~scanf("%d",&n)){
int* table =  new int[1000000];
fill((int*)table,(int*)table+sizeof(table),1);
table[0]=0;

for(int i=1;i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j*=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+1000000,1));
}
}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main() {
	bool prime[N];
	prime[0] = prime[1] = false;

	//initialize
	for(int i=2; i<N; i++) prime[i] = true;
	//Sieve of Eratosthenes
	for(int i=2; i<=N/2; i++){
		if(prime[i]){
			for(int j=2; i*j<=N; j++)
			{
				prime[i*j] = false;
			}
		}
	}

	int countPrime[N];
	int cnt = 0;
	for(int i=0; i<N; i++){
		if(prime[i]){
			cnt++;
		}
		countPrime[i] = cnt;
	}

	int input;
	while(true) {
		cin>>input;
		if(cin.eof()){break;}
		cout<<countPrime[input]<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	unsigned int  n;
	cin >> n;
	unsigned int num, count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(int j = 2; j <=num; j++)
		{
			if(num == j)
                        {
                                count++;
                                break;
                        }
			if(num % j == 0)
			{
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include<stdio.h>

int	main(){
	int	i,	k,	x,	cnt,	data[1000000];
	for(i	=	2;	i	<=	1000000;	i++){
		data[i]	=	1;
	}
	for(i	=	2;	i	*	i	<=	1000000;	i++){
		if(data[i]){
			for(k	=	2	*	i;	k	<=	1000000;	k	+=	i){
				data[k]	=	0;
			}
		}
	}
	while(1){
		cnt	=	0;
		scanf("%d",	&x);
		if(x	==	0)break;
		for(i	=	2;	i	<=	x;	i++){
			if(data[x]	==	1)cnt++;
		}
		printf("%d\n",	cnt);
	}
	return	0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    int n;
    scanf("%d",&n);
    map[0]=0;
    map[1]=0;
    sieve(2);
    for(int i=7;i<1000;i+=6)
    {
        sieve(i);
        sieve(i+4);
    }
    printf("%d\n",count(map.begin(),map.begin()+n+1,1));
    return 0;
}

C++: #include <cstdio>
#define max_n 999999
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        
        
        int ans = 0;
        for(int i =0; i<max_n; i++){
            if(prime[i]>n){
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}