Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2 || num == 5:
		return true
	case num < 2 || num%2 == 0 || num%5 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <cmath>
#define PI 3.14159265359
using namespace std;

bool prime_judge(int x)
{
	for (int i = 2; i < x; ++i) {
		if (x%i == 0)return false;
	}
	return true;
}

int main()
{
	int x, ans;
	while (cin >> x) {
		ans = 0;
		for (int i = 2; i <= x;++i) {
			if (prime_judge(i))++ans;
		}
		cout << ans << endl;
	}
	return 0;
}

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

void Sieve(int n)
{
	bool prime[n+1];
	int c=0;
	memset(prime, true, sizeof(prime));
	int x=sqrt(n*1.0)+2;

	for (int p=2; p<=x; p++)
	{
		if (prime[p] == true)
		{
			for (int i=p*p; i<=n; i+=p)
				{
				    prime[i] = false;
				}

		}
	}
	for (int p=2; p<=n; p++)
	if (prime[p])
		c++;
		cout<<c<<endl;
}

int main()
{
	int n;
	while(cin>>n){
        Sieve(n);
	}

	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
vector<int> prime;

void Prime() {
    prime.emplace_back(2);
    for (int i = 3; i <= 999999; i += 2) {
        bool f = false;
        for (int j = 3; j <= sqrt(i); j += 2) {
            if (i%j == 0) {
                f = true;
                break;
            }
        }
        if (!f) prime.emplace_back(i);
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    Prime();
    int n;
    while (cin >> n) {
        cout << upper_bound(prime.begin(), prime.end(), n) - prime.begin() << endl;
    }
}

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

const int MAX_VALUE = 1000000;

class PrimeNumbers
{
public:
	vector<bool> primeNumbers;

	PrimeNumbers()
	{
		this->createPrimeNumbers();
	}
	
	int answer(int N)
	{
		int result = 0;
		for (int i = 0; i <= N; i++)
		{
			if (this->primeNumbers[i])
			{
				result++;
			}
		}
		return result;
	}

	void createPrimeNumbers()
	{
		
		this->primeNumbers = vector<bool>(MAX_VALUE, true);
		this->primeNumbers[0] = false;
		this->primeNumbers[1] = false;
		for (long long i = 2; i < MAX_VALUE; i++)
		{
			for (long long j = i * i; j < MAX_VALUE; j += i)
			{
				this->primeNumbers[j] = false;
			}
			
		}
	}

};

int main()
{
	int N;
	PrimeNumbers pn = PrimeNumbers();
	
	while(cin >> N)
	{
		cout << pn.answer(N) << endl;
	}
	return 0;
}

C++: #include <stdio.h>
 
int main(){
    int e[30];
 
    int k = 0;
    while( scanf( "%d",&e[k] ) != EOF )k++;
 
    for( int i = 0;i < k;i++ ){
        int n = 1;
        int k = 0;
        while( true ){
            if( e[k] => n ){
                k++;
                n *= 10;
            } else {
                break;
            }
        }
        printf( "%d\n",k );
    }
    return 0;
}

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

using namespace std;
static const int MAXV = 1000000;

int sosuu_list[MAXV];

void make_sosuu_list() {
  for(int i=0;i<MAXV;i++) sosuu_list[i] = 1;
  sosuu_list[0] = sosuu_list[1] = 0;
  for(int i=2;i<MAXV;i++) {
    if(sosuu_list[i]) {
      for(int j=i+i;j<MAXV;j+=i) sosuu_list[j] = 0;
    }
  }
  for(int i=1;i<MAXV;i++)sosuu_list[i]+=sosuu_list[i-1];
}

int main() {
  int n;
  make_sosuu_list();
  while(/*scanf("%d", &n) == 0) {*/!feof(stdin)) {
    scanf("%d", &n);
    if(feof(stdin)) break;
    printf("%d\n", sosuu_list[n]);
  }
}

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

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=1000100;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

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

int main()
{
	int n,c;

	while(cin >> n){
		c = 0;
		bool flag = false;

		for(int i=2;i<n+1;++i){
			for(int j=2;j<i;++j){
				if(i%j == 0)
					flag = true;
			}

			if(!flag)
				++c;
			flag = false;

		}

		cout << c << endl;

	}
	return 0;
}

C++: #include <iostream>

bool Check(int);

int main(void)
{
    int input;
    int count;
    for(int i=0;i < 30;++i){
        std::cin >> input;
        count = 0;
        for(int j=2;j <= input;++j){
            if(Check(j)){
                ++count;
            }
        }
        std::cout << count << std::endl;
    }
    return 0;
}
bool Check(int value)
{
    bool result = true;
    for(int i=value / 2;i >= 2;--i){
        if(value % i == 0){
            result = false;
            break;
        }
    }
    return result;
}

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

int main() {
	int n;
	while(cin >> n && n != EOF) {
		bool* prime = new bool[n+1];
		int count = 0;
		for(int i = 0; i <= n; ++i) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
				cout << i << '\t';
				for(int j = 2 * i; j <= n; j += i) {
					prime[j] = false;
				}
			}
		}
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
				count++;
			}
		}
		
		cout << count << endl;
		delete[] prime;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[80000];
    int n;
    a[0]=2;
    int k=1;
while(cin>>n){
    for(int i=3;i<=n;i+=2){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<k<<endl;
    k=1;
 }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+1000;
const int maxn=1000000+5;
int prime[maxn];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt]=i;
       	cnt++;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	/*for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";*/
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}