Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 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;
}

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