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>

using namespace std;

int main(){
	int n;
	bool p[1000000] = { true };
	int ans[1000000] = { 0 };
	p[0] = false;
	p[1] = false;

	for (int i = 2; i < 1000; i++){
		if (p[i]){
			for (int j = i*i; j < 1000000; j+=i){
				p[j] = false;
			}
		}
	}

	for (int i = 0; i < 1000000; i++){
		ans[i] += p[i];
	}

	while (cin >> n)
		cout << ans[n] << endl;

}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

const int SIZE = 1000000;
bool is_prime[SIZE];
vector<int> primes;
int main()
{
	fill(is_prime, is_prime+SIZE, true);
	for (int i = 2; i < SIZE; ++i)
	{
		if (is_prime[i])
		{
			for (int j = 2*i; j < SIZE; j += i)
				is_prime[j] = false;
			primes.push_back(i);
		}
	}

	int n;
	while (scanf("%d", &n) != EOF)
		if (n < 2)
			puts("0");
		else
			printf("%d\n", upper_bound(primes.begin(), primes.end(), n) - primes.begin() - 1);

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
        int n;
        int d; //素数を入れるための添字
        bool count; //割りきれるかどうかの判定
        int number[400000]; //素数を入れておく
        number[0] = 2;
        
        
 
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++)
                                if(i % number[j] == 0)
                                        count = false;
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                
        cout << d+1 << endl;
        }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<cmath>
#define mem0(x) memset(x,0,sizeof(x))
#define memff(x) memset(x,0xff,sizeof(x))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define per(i,b,a) for(int i=b;i>a;i--)
#define perr(i,b,a) for(int i=b;i>=a;i--)
#define MAX_N 5050
#define MAX_M 5050
#define MAX_P 1000010
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
map<int,int> m;
const int INF=1<<29;
const int MOD=1e9+7;
int par[MAX_N];
int rank[MAX_N];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int GCD(int a,int b){if(b==0) return a;return GCD(b,b%a);}
void init(int n){rep(i,0,n){par[i]=i;rank[i]=0;}}
int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
void unite(int x,int y){x=find(x);y=find(y);if(x==y) return;if(rank[x]<rank[y]){par[x]=y;}else{par[y]=x;if(rank[x]==rank[y])rank[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
struct node{int x,y;};
bool cmp(int x,int y){return x>y;}
bool ccmp(node x1,node x2){return x1.x>x2.x;}
LL mod_pow(LL x, LL n,LL mod){LL res=0;while(n>0){if(n&1) res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
int prime[MAX_P];
bool is_prime[MAX_P];
int x;
int sieve(int  n)
{
    int p=0;
    repp(i,0,n)
    {
        is_prime[i]=true;
    }
    is_prime[0]=is_prime[1]=false;
    repp(i,2,n)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i)
            is_prime[j]=false;
        }
    }
    return p;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(~scanf("%d",&x))
    {
        printf("%d\n",sieve(x));
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define MAX 1000000
#define SQRTMAX 1000
void seive_prime(bool seive[])
{
	for(int i=2;i<=SQRTMAX;i++) {
		if(seive[i] == false) {
			for(int j=i*2;j<=MAX;j+=i) {
				seive[j]=true;
			}
		}
	}
}
int main() {
	int n;
	bool sieve[MAX+1] = {false};
	// エラトステネスの篩
	seive_prime(sieve);
	
	while(cin >> n) {
		int cnt = 0;
		for(int i=2;i<=n;i++) {
			if(sieve[i] == false)
				cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int main(){
  bool prime[1000000] = {};
  int sum[1000000]; sum[0] = sum[1] = 0; sum[2] = 1;
  for(int i = 3 ; i < 1000000 ; i += 2 ){
    sum[i] = sum[i + 1] = sum[i - 1];
    if(!prime[i]){
      for(int j = i + i + i ; j < 1000000 ; j += i + i ){
        prime[j] = true;
      }
      sum[i]++;
      sum[i+1]++;
    }
  }
 
  int n;
  while(cin >> n){
    cout << sum[n] << endl;
  }
}

C++: #include <iostream>
#include <cstring>
using namespace std;
#define maxn 1000000

int  isprime(int n)
{
  
  bool prime[maxn];
  int p = 0;
  memset(prime,true,sizeof(prime));
  prime[0] = prime[1] = false;
  for(int i=2;i<=n;i++)
  {
    if(prime[i])
    {
      for(int j=2*i;j<=n;j+=i) prime[j] = false;
      p++;
    }
  }

  return p;
}

int main()
{

    int n;
    while(cin>>n)
    {
      cout<<isprime(n)<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
bool ifprime(int i);
int numbers[31];
int nn[31];
int num = 0;
int main()
{
	int n, count;
	bool ans;
	while ((scanf("%d", &n)) != EOF)
	{
		if (num > 0)
		{
			for (int i = 0; i <= num; i++)
			{
				if (n == numbers[i])
				{
					printf("%d\n", nn[i]);
					break;
				}
			}
		}
		else
		{
			count = 0;
			for (int i = 2; i <= n; i++)
			{
				ans = ifprime(i);
				if (ans == true)
				{
					++count;
				}
			}
			printf("%d\n", count);
			numbers[num] = n;
			nn[num] = count;
			num++;
		}
	}

	return 0;
}
bool ifprime(int i)
{
	int m = (int)sqrt(i);
	for (int j = 2; j <= m; j++)
	{
		if (i% j == 0)
		{
			return false;
		}
	}
	return true;
}

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

static bool sieve[1000010];
static int primecount[1000010];

int main() {
	fill(sieve, sieve+1000010, true);
	sieve[0]=sieve[1]=false;
	primecount[0]=primecount[1]=0;
	int partial_count = 0;
	for(int i = 2; i < 1000010; i++) {
		primecount[i] = partial_count;
		if(!sieve[i])continue;
		primecount[i] = ++partial_count;
		if(i<10000)
			for(int j = i*i; j < 1000010; j+=i) {
				sieve[j]=false;
			}
	}
	while(true) {
		int n; if(scanf("%d", &n)<1)break;
		printf("%d\n", primecount[n]);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int prime[80000];
    int ptr=2;
    prime[0] = 2;
    prime[1] = 3;
    for(int num=5; num<1000000; num+=2){
        bool f = false;
        for(int i = 0; i<ptr; i++){
            if (prime[i]*prime[i] > num) break;
            if (num%prime[i]==0) {
                f = true;
                break;
            }
        }
        if(!f) prime[ptr++] = num;
    }
    prime[ptr]=1000001;
    int n;
    while(cin >> n){
        int k=0;
        for(;prime[k]<=n;k++);
        cout << k << endl;
    }
     
    return 0;
}