Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define ll long long
//#define scanf scanf_s
bool p[1000005];
int main()
{

	REP(i, 1000000) p[i] = true;
	p[0] = p[1] = false;
	for (int i = 2; i*i <= 1000000; i++)
	{
		if (p[i] == true)
		{
			for (int j = 2; j*i <= 1000000; j++)
			{
				p[i*j] = false;
			}
		}
	}
	int n;
	while (cin >> n)
	{
		int cnt = 0;
		REP(i, n + 1)
		{
			if (p[i] == true) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

//using namespace std;

int sosuu(int n);

int main(){
    int n = 0;
    
    while(scanf("%d",&n)!=EOF){
        int temp = 0;
        if(n==1){
            printf("%d\n",0);
        }else{
            for(int i=2; i<=n; i++ ){
                temp+=sosuu(i);
                if(i!=2){
                    i++;
                }
            }
            printf("%d\n",temp);
        }
    }
}

int sosuu(int n){
    int temp=1;
    for(int i=0; i<n; i++){
        temp=temp*7;
    }
    if(temp%n!=7%n){
        return 0;
    }
    return 1
    ;
}

C++: #include<cstdio>
using namespace std;
#define max 1000000
bool p[max];
int main(){
    p[1] = true;
    for(int i = 2; i * i < max; i++){
		if(p[i]) continue;
		for(int j = i * i; j < max; j+=i) p[j] = true;
	}
    int n;
    while(~scanf("%d",&n)){
		int ans = 0;
		for(int i = 1; i <= n; i++){
			if(!p[i])ans++;
		}
		printf("%d\n",ans);
	}
    return 0;
}

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;
}