Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

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
}

C++: #include <iostream>
using namespace std;
int main(){
    bool is_prime[1000000];

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

    for(int i=2; i*i<1000000; i++){
        if(is_prime[i]){
            for(int j=i*i; j<1000000; j+=i){
                is_prime[j] = false;
            }
        }
    }
    int n_prime[1000000];
    int cnt = 0;
    for(int i=0; i<1000000; i++){
        if(is_prime[i]){
            cnt++;
        }
        n_prime[i] = cnt;
    }
    while(true){
        int n;
        cin >> n;
        if(cin.eof())
            break;
        cout << n_prime[n] << endl;
    }
    return 0;
}

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

int main() {
	int n;
	while(cin >> n) {
		vector<int> a(n, 1);
		a[0] = 0;

		for(int i=1; i<(int)sqrt(n); i++) {
			if(a[i] == 1) {
				for(int j=i+1; (i+1)*j<=n; j++) { // 素数の倍数のフラグを消していく
					a[(i+1)*j-1] = 0;
				}
			}
		}

		int ans = 0;
		for(int i = 0; i<n; i++) {
			if(a[i] == 1) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
#define MAX 80000
using namespace std;

int main(){
	int n;
	int prime[MAX],i,j;
	int count;
	bool flag;

	while((cin >> n)!= NULL){
		count = 0;
		for(i = 3; i <= n; i+=2){
			flag = true;
			for(j = 0; j < count; j++){
				if(i % prime[j] == 0){
					flag = false;
					break;
				}
			}
			if(flag == true){
				prime[count++] = i;
			}
		}
		if(n > 1)	count++; //2
		cout << count << endl;
		//delete[] prime;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int ans[999999];

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

int main() {
    FOR(i, 1, 999999) {
        ans[i] = ans[i-1] + isprime(i+1);
    }
    int i;
    while(cin >> i) {
        cout << ans[i-1] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	int n;
	while (scanf_s("%d", &n) != EOF) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

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

int main(){
	char nums[1000000];
	int n;
	for(int i = 2; i < 1000000; i++)
		nums[i] = 1;
	for(int j = 2; j < 1000; j++)

		for(int k = 2; j * k <= 1000000; k++)
			nums[j * k] = 0;
	while(cin >> n){
		int count = 0;
		for(int l = 2; l <= n; l++)
			if(nums[l])
				count++;
		cout << count << endl;
	}
	return 0;
}

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

int main()
{
	bool isPrime[1000000];
	int num[1000000];
	memset(isPrime,false,sizeof(isPrime));
	isPrime[0]=isPrime[1]=true;
	for (int i = 2; i < 1000000; i++) {
		if(isPrime[i])
		{
			num[i]=num[i-1];
			continue;
		}

		for(int j=i*2;j<1000000;j+=i)
		{
			isPrime[j]=true;
		}
		num[i]=num[i-1]+1;
	}

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

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

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

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

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

int sieveOfEratosthenes(int n) {
    vector<int> prime;
    vector<int> isPrime((unsigned long)n + 1, true);
    isPrime[0] = false, isPrime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            prime.push_back(i);
            for (int j = 2 * i; j <= n; j+= i)
                isPrime[j] = false;
        }
    }
    return (int)prime.size();
}

int main() {
    int n;
    while (cin >> n) {
        cout << sieveOfEratosthenes(n) << endl;
    }
    return 0;
}

C++: #include <cstdio>
int d[1000000],c[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i]){c[i]=r;continue;}
		c[i]=++r;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int *p=upper_bound(prime,prime+num,n);
        int ans=p-prime;
        cout<<ans<<endl;
    }
    return 0;
}

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

int prime(int number) {
    int s_num = sqrt(number);
    if (number == 2) {
        return 1; 
    } else if (number % 2 == 0) {
        return 0;
    }
    for (int i = 3; i <= s_num; i += 2) {
        if (number % i == 0) {
            return 0;
        }
    }
    return 1;
}

int main(void) {
    int number;
    int count;

    while (std::cin >> number) {
        count = 0;
        for (int i = 2; i <= number; i++) {
            if (prime(i) == 1) {
                count++;
            }
        }
        std::cout << count << std::endl;

    }
    return 0;
}

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

#define rep(i, n) for(int i = 2; i <= n; i ++)

using namespace std;

int main(void){
	for(int n, count = 0; cin >> n; cout << count << endl, count = 0){
		vector<bool> numberList(n + 1);

		rep(i, n) numberList[i] = true;

		for(int i = 2; i * i <= n; i ++) for(int j = i; i * j <= n; j ++) numberList[i * j] = !(numberList[i * j]);
		
		rep(i, n) if(numberList[i]) count ++;
	}

	return 0;
}