Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [31]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 sieve_of_eratosthenes(int n){
  int p = 0; //素数の数
  int primes[n];
  bool is_prime[n+1]; 
  for(int i=0;i<=n;i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false; //0,1は素数じゃない
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      primes[p++] = i;
      for(int j= i*2;j<=n;j+=i) is_prime[j] = false;
    }
  }
  return p;
}

int main(){
  int n;
  while(cin >> n){
    cout << sieve_of_eratosthenes(n) << endl;
  }
}

C++: #include <bits/stdc++.h>
#define MAX_N 1000001
using namespace std;
bool prime[MAX_N];
int table[MAX_N];

void initialize() {
    int p = 0;
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false;
    for(int r = 2; r * r <= MAX_N; r++) {
        if(prime[r]) {
            table[p++] = r;
            for(int c = r * 2; c <= MAX_N; c+= r) {
                prime[c] = false;
            }
        }
    }
}


int main(void) {
    initialize();
    int num;
    while(cin >> num) {
        int cnt = 0;
        for(int r = 0; table[r] <= num; r++) {
            //cout << table[r];
            //putchar(' ');
            cnt++;
        }
        //putchar('\n');
        cout << cnt << endl;
    }
    return(0);
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    int a[n];
    for(int i=0;i<n;i++){
      a[i]=1;        //1 素数　０素数ではない
    }
    a[0]=0;
    cont=0;
    for(int i=2;i<=sqrt(n);i++){
      if(a[i-1]==1){
	for(int j=2;i*j<=n;j++){
	  //	  cout << j << " " << n << endl;
	  a[i*j-1]=0;
	}
      }
    }
    for(int i=0;i<=n;i++){
      //cout<<i+1<<" "<<a[i]<<endl;
      if(a[i]==1)cont++;
    }
    cout<<cont<<endl;
  }
}

C++: #include <stdlib.h>
#include <stdio.h>
const int MAX_V = 1000000; // 100????????§?´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????? 
int pcount[MAX_V+1];
int main() {
    int i, k,a,sum=0;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1; // 2??\????´???°??¨??????
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°2?????\????????°?´???°??§?????? 
            }
            
        } 
        
    }
    pcount[0]=0;
    pcount[1]=0;
    for(i=2;i<MAX_V;i++){
        if(prime[i]){
            sum++;
        }
        pcount[i]=sum;
    }
    for(i=0;i<30;i++){
        scanf("%d",&a);
        printf("%d\n",pcount[a]);
    } 

    return 0; 
    
}

C++: #include<iostream>
using namespace std;
int main(){
  long n;
  int count1,count2;
  while(1){
    cin >>n;
    count2=0;
    for(int i=n;i>1;i--){
      count1=0;
      for(int j=2;j<i;j++){
	if(i%j==0){
	  count1++;
	  break;}
      }
      if(count1==0)count2++;}
      cout <<count2<<endl;
    }
  return 0;
}

C++: 



#include <iostream>
#include <vector>
#include <cmath>
using namespace std;


int main(void)
{
	int n;
	vector<int> vecPrime;

	while (cin >> n)
	{
		// vectorの破棄
		vecPrime.clear();

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			vecPrime.push_back(2);
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい
			int size = vecPrime.size();
			for (int j = 1; j < size && vecPrime[j] < sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % vecPrime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				vecPrime.push_back(i);
			}
		}

		cout << vecPrime.size() << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main() {
	int n,ans=0,i,count=0;
	int dp[100][100];
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			dp[i][j] = -1;
		}
	}
	while (cin >> n) {
		for (i = 2; i <= n; i++) {
			for (int j = 2; j <= i; j++) {
				if (dp[i][j] == -1) {
					dp[i][j] = i%j;
				}
				if (dp[i][j] == 0 ) {
					count++;
				}
			}
			if (count == 1) {
				ans++;
			}
			count = 0;
		}
		cout << ans << endl;
		ans = 0;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 999999 + 10;
bool is_prime[maxn];
int tot[maxn];

void sieve(int n){
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;
	
	for(int i=2; i*i <= n; i++) if(is_prime[i])
		for(int j=2*i; j <= n; j+=i)
			is_prime[j] = false;	
}

int main(){
//	freopen("data/in.txt", "r", stdin);
	
	sieve(maxn-1);
	int cnt = 0;
	for(int i=0; i<maxn; i++){
		if(is_prime[i]) cnt++;
		tot[i] = cnt;
	}
	
	int n;
	while(1==scanf("%d", &n)){
		printf("%d\n", tot[n]);
	}

	return 0;
}

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

bool prime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    for (int i = 3; i * i <= num; i += 2) {
        if (num % i == 0) return false;
    }

    return true;
}

int main() {
    int ans[1000000], n;
    ans[0] = 0;
    for (int i = 1; i <= 999999; ++i) {
        if (prime(i)) ans[i] = ans[i - 1] + 1;
        else ans[i] = ans[i - 1];
    }

    while (cin >> n) {
        cout << ans[n] << endl;
    }
    
    return 0;
}

C++: #include<iostream>
int main(){
	int n;
	while(1){
		std::cin>>n;
		if(std::cin.eof())break;
		int m=0,l=0;
		for(int i=2;i<n;i++){
			for(int j=1;j<=i;j++){
				if(i%j==0)m++;
			}
			if(m==2)l++;
			m=0;
		}
		std::cout<<l<<std::endl;
	}
	return 0;
}

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

using namespace std;
int main() {
  long n;
  vector<long> primes;
  primes.push_back(2);
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 3; i <= n; i += 2) {
      bool prime = true;
      for (unsigned int j = 0; j < primes.size() && primes[j] * primes[j] <= n; j++)
        if (i % primes[j] == 0) {
          prime = false;
          break;
        }
      if(prime) primes.push_back(i);
    }
    int x = 0;
    for (long& e: primes)
      if (e <= n) x++;
    cout << x << endl;
  }
}

C++: #include <stdio.h>

int main(){

	int a[99999] = {2,3,5},i,n,m=0,b=3,c=0;
	while (scanf("%d",&n)!=EOF){
		for (i = 2; i < n+1; i++){
			if (i % a[m] == 0){
				a[b] = i, b++, c++;
				}
		}printf("%d\n", c);
		}
	return 0;
}

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

#define add push_back
#define inf 2147000000

#define rep(i,n) for(int i=0;i<n;i++)
#define out(a) cout<<a<<endl;

using namespace std;

int main(void){
	int sosuu[50000];
	int cont=0;
	int n;
	scanf("%d",&n);
	
	for(int i=2;i<=n;i++){
		for(int j=0;;j++){
			if(j==cont){
				sosuu[cont]=i;
				cont++;
				break;
			}
			if(i%sosuu[j]==0){
				break;
			}
		}
	}
	out(cont);
}

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

int main()
{
	int n[30];
	int i = 0;
	while(cin >> n[i]) {i++;}
		
	for (int k = 0;k < i;k++){
		int s = 0;
		for (int j=3;j<=n[k];j++){
			int y = 0;
			for (int m=1;m<=j;m++){
				if (j%m == 0){y++;}
			}
			if (y == 2){s++;}
		}
		cout << s << endl;
	}	
    return 0;
}