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;

long n,ans;

int main(){
	cin >> n;
	ans = 1;
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}
	if(n == 2){
		cout << 1 << endl;
		return 0;
	}
	for(long i=3;i<=n;i=i+2){
		ans += 1;
		for(long j=3;j*j<=i;j=j+2){
			long k = i/j;
			if(i == k*j){
				ans -= 1;
				break;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define loop(i, a, b) for(int i = a; i < b ; i++)
#define rep(i, a) loop(i, 0, a)
#define MAX 1000000

int main()
{
  bool prime[MAX];
  rep(i, MAX) prime[i] = true;
  prime[0] = prime[1] = false;
  loop(i, 2, sqrt(MAX)){
    for(int j = i * 2; j < MAX; j += i){
      prime[j] = false;
    }
  }
  
  int n;
  while(cin >> n) {
    int cnt = 0;
    loop(i, 2, n + 1) if(prime[i] == true) cnt++;
    cout << cnt << endl;
  }
}

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

vector <int> prime;
bool is_checked[1000010] = {false};

int main() {
	// Eratosthenes
	is_checked[0] = true; is_checked[1] = true;
	for(int i = 2; i < 1000000;i++){
		if (is_checked[i]) continue;
		prime.push_back(i);
		for(int j = 1;;j++) {
			if(i*j > 1000000) break;
			is_checked[i*j] = true;
		}
	}

	int n;
	while(cin >> n) {
		int count = 0;
		for (int i = 0;;i++) {
			if (prime[i] > n) break;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main (){
    
    /*?´???°???????´?????????????*/
    vector<int>Primenumber(MAX+1,0);
    /*?´???°???????´???????????????????*/
    int counter =0; int n;
    while(cin >> n){
        bv check(MAX+1,true);
    for(int i = 2; i<=n;i++){
        if(check[i]){
            /*true?????£?????¨???????????°????????????false??§?????????*/
            for(int j = 2;i*j<=n;j++)
                check[i*j] = false;
            Primenumber[counter] = i;
            counter++;
        }
    }
    int ans = 0;
    for(int i = 2;i<=n;i++)
        if(check[i])
            ans++;
    cout << ans << endl;
    }
}

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

using namespace std;

bool isprime(int N)
{
	for (int I = 2; I <= sqrt(N); I++)
	{
		if (N % I == 0) return false;
	}

	return true;
}

int main()
{
	int n;

	int c = 0;

	for (int i = 2; i <= n; i++)
	{
		if (isprime(i) == true)
		{
			c += 1;
		}
	}

	cout << c << endl;

	return 0;
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
int prime[1000005];
bool is_prime[1000005];
int seve(int n)
{
    int p=0;
    for(int i=0;i<=n;i++)
        is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i)
                is_prime[j]=false;
        }
    }
    return p;
}
int main(void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",seve(n));
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=999999+10;
int n,cnt;
int pre[maxn],prime[maxn];
int bina_search(int l,int r){
	int mid=(l+r)/2;
	if((prime[mid]<n&&prime[mid+1]>n)||prime[mid]==n)
		return mid;
	if(prime[mid]<n)
		bina_search(mid+1,r);
	else
		bina_search(l,mid);
}
int main(){
	memset(pre,0,sizeof(pre));
	memset(prime,0,sizeof(prime));
	int t=1;
	for(int i=2;i<maxn;i++){
		if(!pre[i])
			prime[t++]=i;
		for(int j=1;j<=t&&i*prime[j]<maxn;j++){
			pre[prime[j]*i]=prime[j];
			if(i%prime[j]==0)
					break;
		}
	}
	for(int i=1;i<100;i++)
        cout<<prime[i]<<" ";
	while(scanf("%d",&n)!=EOF){
		cnt=bina_search(2,n);
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n){
    int i;
    if(n == 2)  return true;
    else if(n < 2 || n % 2 == 0)    return false;
    else{
        i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)  return false;
            i += 2;
        }
    }
    return true;
}
 
int main(void){
    int n, i, cnt;
    while(cin >> n){
        cnt = 1;
        for(i = 3; i <= n; i = i + 2){
            if(isPrime(i))  cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main(){
	const int max_num=1001000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[169]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 ,1009 };
	int sosuu=0;
	int k=169;

	for(int i=0;i<169;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1011;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<169;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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

const int M = 110000;

bool p[M];
int prime_n[M];

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

  int count = 0;
  for(int i = 2; i < M; i++) {
    if(p[i]) prime_n[i] = ++count;
    else prime_n[i] = count;
  }
}

int main() {
  prime();
  
  int n;
  while(cin >> n) {
    cout << prime_n[n] << endl;
  }
}

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

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		vector<int> prime;
		
		if (n >= 2){
			prime.push_back(2);
		}
		for (int i = 3; i <= n; i += 2){
			int j;
			for (j = 1; j < prime.size(); j++){
				if (i % prime[j] == 0){
					break;
				}
			}
			if (j == prime.size()){
				prime.push_back(i);
			}
		}
		printf("%d\n", prime.size());
	}
	
	return 0;
}