Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [40]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;
const int MAX = 1000000;

int main(){
	bool b[MAX] = {true};
	static int a[MAX] = {0,0};
	int n;
	for(int i = 2;i < MAX;i++){
		if(!b[i]){
			for(int j = 2;i*j < MAX;j++){
				b[i*j] = true;
			}
		}
		a[i] = a[i-1] + !b[i];
	}
	while(cin >> n){
		cout << a[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int n;

  while ( cin >> n )
    {
      unique_ptr<int[]> tbl(new int[n+1]);
      for ( int i = 2; i <= n; i++ )
        tbl[i] = 1;

      for ( int i = 2; i <= n; i++ )
        if ( tbl[i] == 1 )
          {
            int j = i * 2;
            while ( j <= n )
              {
                tbl[j] = 0;
                j += i;
              }
          }

      int ret = 0;
      
      for ( int i = 2; i <= n; i++ )
        ret += tbl[i];

      cout << ret << endl;
    }
  
  return 0;
}

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

using namespace std;

#define MAX_NUM	1000000

int solist[MAX_NUM] = { 0 };

int main(int argc, char* argv[])
{
	int i; 
	int num;
	int count;
	int val;

	solist[0] = 1;
	solist[1] = 1;

	for (num = 3; num < MAX_NUM; num += 2) {
		if (solist[num]) continue;
		for (i = num * 2; i < MAX_NUM; i += num) {
			solist[i] = 1;
		}
	}

	while (cin >> val) {
		count = 1;
		for (i = 1; i <= val; i += 2) {
			if (solist[i] == 0) {
				count++;
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
#define MAX 1000//1000010

int main(){
	bool prime[MAX];
	prime[0]=prime[1]=0;
	for(int i=0;i<MAX;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=2;i<MAX;i++){
		if(prime[i]==1){
			for(int j=2;i*j<MAX;j++){
				prime[i*j]=0;
			}
		}
	}
	int prime_under_num[MAX];
	prime_under_num[0]=0;
	for(int i=1;i<MAX;i++){
		prime_under_num[i]=prime_under_num[i-1]+prime[i];
	}
	
	int n;
	while((scanf("%d",&n))!=EOF){
		printf("%d\n",prime_under_num[n]);
	}
	
	
}

C++: #include<iostream>
using namespace std;
int main(){
int a,i;
cin>>a;
for(int x=0;x<a;x++){
if(a%x){i++}
cout<<i<<endl;
}
return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair

vector<ll> getPrimesFast(ll n){
    vector<ll> primes;
    if (n < 10000){
        primes.clear();
        if (n < 2){
            return primes;
        }
        primes.push_back(2);
        if (n == 2){
            return primes;
        }
        primes.push_back(3);
        if (n == 3){
            return primes;
        }
        for(ll i = 5; i <= n; i += 2){
            bool isPrime = true;
            for(int p = 0; p < (int)primes.size(); ++p){
                if (i % primes[p] == 0){
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                primes.push_back(i);
            }
        }
        return primes;
    }
    else{
        vector<ll> sieve = getPrimesFast(sqrt(n));
    
        vector<short> isPrime(n+1, 1);
        for(int i = 0; i < (int)sieve.size(); ++i){
            for(int j = sieve[i] * 2; j <= n; j += sieve[i]){
                isPrime[j] = 0;
            }
        }

        for(int i = 2; i <= n; ++i){
            if (isPrime[i]){
                primes.push_back(i);
            }
        }
        return primes;
    }
}

int main(void)
{
    cin.sync_with_stdio(false);
    int n;

    auto primes = getPrimesFast(1000000);

    while(cin >> n) {
        auto itr = upper_bound(ALL(primes), n);
        cout << itr - primes.begin() << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,k=0;
	vector<int> pri(1000000);
	for(int i=0;i<1000000;i++)
		pri[i]=1;
	pri[0]=0;
	pri[1]=0;
	for(int i=0;i*i<n;i++){
		if(pri[i]){
			for(int j=i*2;j<1000000;j+=i)
				pri[j]=0;
		}
	}
	cin>>n;
	int i=0;
	while(k<=n)
	if(pri[k++])
	i++;
	cout<<i<<endl;
	
	
	
	return 0;
}

C++: #include <cstdio>
#define SIZE 1000001

int main(void)
{
  int i, j, k, n;
  int memo[SIZE] = {};

  memo[0] = 1;
  memo[1] = 1;
  for (i = 2; i <= SIZE; i++) {
    if (memo[i] == 0) {
      for (j = i * 2; j <= SIZE; j = j + i) {
        memo[j] = 1;
      }
    }
  }
  
  while (scanf("%d", &n) != EOF) {
    k = 0;
    for (i = n; i > 0; i--) {
      if (memo[i] == 0) k++;
    }
    std::printf("%d\n", k);
  }
}

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

using namespace std;





int main()
{
	int n;
	while (cin >> n) {
		int count=0;
		bool prime[1000000];
		fill(prime, prime + n, true);
		prime[0] = false;
		prime[1] = false;
		for (int i = 1; i <= n; i++) {
			if (prime[i]) {
				for (int j = 2 * i; j <= n; j += i) {
					prime[j] = false;
				}
			}
		}
		for (int i = 1; i <= n; i++) {
			if (prime[i]) count++;
		}
		cout << count << endl;
	}





}

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

#define N 1000000

using namespace std;

int main(void){
	bool prm[N];
	for(int i=0;i<N;i++)prm[i]=true;
	int upto = (int)sqrt(N);
	for(int i=2;i<=upto;i++){
		if(prm[i]){//消されてなければその倍数を消す
			for(int j=2;i*j<=N;j++) prm[i*j] = false;
		}
	}
	int n;
	while(cin >> n){
		int count = 0;
		for(int i=2;i<=n;i++){
			if(prm[i]) count++;
		}
		cout << count << "\n";
	}
	return 0;
}

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

#define MAX 1000000

int prime[MAX]={};

void eratos(void){
	int i,j;
	prime[0] = 1;
	prime[1] = 1;
	for(i = 2;i < MAX/2;i++){
		for(j = 2;i*j <= MAX;j++){
			prime[i*j] = 1;
		}
	}
}

int main(void){
	long i,j;
	long n;
	int cnt;
	int prime_cnt;

	eratos();
	while(scanf("%ld",&n) != EOF){
		prime_cnt = 0;
		for(i = 0;i <= n;i++){
			if(prime[i] == 0)
				prime_cnt++;
		}
		/*prime_cnt = 0;
		for(i = 0;i < n+1;i++){
			cnt = 0;
			if(i < 2) continue;
			if(i == 2){
				prime_cnt++;
				continue;
			}
			for(j = 2;j <= i/2;j++){
				if(i % j == 0){
					cnt++;
					break;
				}
			}
			if(cnt == 0) prime_cnt++;
		}
		printf("%d\n",prime_cnt);*/		
		printf("%d\n",prime_cnt);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;


int sum[1000010];
void init(){
    for(int i = 2 ; i <= 1000000 ; i++){
        sum[i] = sum[i-1] + 1;
        for(int j = 2 ; j*j <= i ; j++){
            if( i % j == 0 ){
                sum[i]--;
                break;
            }
        }
    }
}
int main() {
    init();
    int n;
    while( cin >> n && n ){
        cout << sum[n] << endl;
    }
}