Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int cnt=0,res=0;
    for(int i=3; i<=n; i+=2){
      for(int j=1; j<=i; j++){
        if(i%j == 0) cnt++;
      }
      if(cnt==2) res++;
      cnt = 0;
    }
    cout << res+1 << endl;
  }
  return 0;
}

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

int eratos(forward_list<int> xs) {
	if (xs.empty()) return 0;
	int head = xs.front();
	xs.pop_front();
	xs.remove_if([&](int n){
		    return !(n%head);
		    });
	return 1+eratos(xs);
}

int main() {
	int n;
	while (cin>>n) {
		forward_list<int> ls(n-1);
		iota(begin(ls),end(ls),2);
		cout << eratos(ls) << endl;
	}
	return 0;
}

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,max;
	int count[N_MAX];
	bool so[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		so[i]=true;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	so[0]=so[1]=false;
	for(j=4;j<=max;j+=2)
			so[j]=false;
	for(i=3;i<=1000;i+=2){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=false;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;
	while(cin >> n){
		count = 0;
		for(int i = 2; i <= n; i++){
			if(i == 2){
				count++;
			}
			else if(i % 2 != 0){
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
						break;
					}
				}
				if(flag != true){
					count++;
				}
				flag = false;
			}
		}

		cout << count << endl;

	}

	return 0;
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int i=0;
  int j=0;
  int n=0;
  int a[1000000]={};
  int sum=0;

  while(scanf("%d",&n)!=EOF)
    {
      for(i=0;i<1000000;i++)
        a[i]=1;
      sum=0;

      for(i=2;i<=n;i++)
        {
          if(a[i-1]==0)
            continue;
          for(j=2;j<=n/i;j++)
            a[i*j-1]=0;
        }

      for(i=1;i<n;i++)
        sum+=a[i];

      cout<<sum<<endl;

    }


  return 0;

}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
bool isprime[1000000];
vector<lnt> primes;

int main()
{
	fill(isprime,isprime+1000000,1);
	isprime[0]=isprime[1]=0;
	for(lnt i=2;i<1000000;i++){
		if(!isprime[i]) continue;
		primes.push_back(i);
		for(lnt j=2*i;j<1000000;j+=i) isprime[j]=0;
	}
	lnt n;
	while(scanf("%lld",&n)!=EOF){
		cout<<upper_bound(primes.begin(),primes.end(),n)-primes.begin()<<endl;
	}
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 1;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 1;
	for (int i = 1;i<=num;i++) {
		
		for (int j=2;j<i;j++) {
			if (i%j==0) {
				count ++;
				break;
			}
			
		}
	}
	cout << (num-count) <<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
 
int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

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

}

//0009
int main()
{
	int n;
 
	while(cin >> n){
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}

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

bool prime_number(int n);
int proceed;
bool pn[1000000];

int main(int argc, char** argv) {
	int n, i, result;

	while(std::cin >> n) {
		if(n < 2) {
			result = 0;
		}else {
			result = 1;
			for(i = 3; i <= n; i += 2) {
				if(prime_number(i)) {
					result++;
				}
			}
		}
		std::cout << result << std::endl;
	}
}

bool prime_number(int n) {
	if(n <= proceed){
		return pn[n];
	}
	proceed = n;
	int i;
	double rt = sqrt(n);
	if(n < 2) {
		return false;
	}else if(n == 2) {
		pn[2] = true;
		return true;
	}else if(n % 2 == 0) {
		return false;
	}
	for(i = 3; i <= rt; i += 2) {
		if(n % i == 0) {
			return false;
		}
	}
	pn[n] = true;
	return true;
}