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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		sosu[i]=(flag)? cnt++ : cnt;		
	}
	//for(int i=0;i<30;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

bool is_prime(int n)
{
    if(n<=1)
        return false;
    for(int i=2; i*i<=n; i++){
        if(n%i==0)
            return false;
    }
    return true;
}

int gcd(int a, int b)
{
    if(b==0)
        return a;

    return gcd(b, a%b);
}

int main(){
    bool is_prime[1000000];

    is_prime[0] = is_prime[1] = false;

    for(int i=2; i<1000000; i++){
        is_prime[i] = true;
    }

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

    int n_prime[1000000];

    int cnt = 0;
    for(int i=0; i<1000000; i++){
        if(is_prime[i]){
            cnt++;
        }
        n_prime[i] = cnt;
    }

    while(1){
        int n;
        cin >> n;
        if(cin.eof()){
            break;
        }
        cout << n_prime[n] << endl;
    }
}

C++: ///BISMILLAHIR RAHMANIR RAHMIM
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000002
int pri[MAX+2];
int cnt[MAX+2];
void sieve(int n)
{
    pri[1]=1;
    for (int i=2;i<=n;i++)
    {
        if(pri[i]==0)
        {
            for (int j=i+i;j<=n;j+=i)
            {
                pri[j]=1;
            }
        }
    }
    int tot = 0;
    for(int i = 1;i<=n;i++)
    {
        if(pri[i]==0)
            tot++;
        cnt[i] = tot;
    }
}
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    sieve(MAX);
    int n;
    while(cin>>n)
    {
        cout << cnt[n] << "\n";
    }
    return 0;
}

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

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

int main()
{
	long int n,x;
	int ans;
	while(cin>>n){
		ans=0;
		for(x=1;x<=n;x++){
			if(is_sosu(x)==true) ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define ll long long
#define mx 1000000+7
bool a[mx+10];
ll pr[mx], p;

using namespace std;
ll sieve(ll n);
int main()
{
    ll i, j,k, l, m, n;
   while(scanf("%lld", &n)==1)
   {
       m = sieve(n);
    printf("%lld\n", m);
   }

}
ll sieve(ll n)
{
    p = 0;
    ll i, j, k;
    k = sqrt(n);
    pr[p++] = 2;
    for(i = 4; i <= n; i+=2)
        a[i]=1;
    for(i = 3; i <= n; i+=2)
    {
        if(a[i] ==0)
            pr[p++]=i;
        if(i <= k)
            if(a[i] == 0)
        {
            for(j = i*i; j <= n; j+=2*i)
                a[j]=1;
        }
    }
    return p;
}

C++: #include <cstdio>
#include <memory.h>

int n;
int MAX_N=1000004;
bool DP[1000005] ;//素数リスト「素数じゃなかったらtrue」


int main()
{
	memset(DP,false,sizeof(DP));
	while(scanf("%d",&n)!=EOF)
	{
	 	int count=0;
		for(int i=1;i<n;i++)
		{
			DP[0]=true;
			DP[1]=true;
			if(DP[i]==false)
			{
				count++;
				for(int j=i*2;j<MAX_N;j+=i)DP[j]=true;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

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

int main() {
  int n;
  int sum=0;
  
  vector<int>primelist(1000010);
    primelist.at(2)=1;
    primelist.at(3)=1;
  
  for(int i=3;i<1000001;i++){
    for(int j=2;j<=sqrt(i);j++){
      
      if(i%j==0){
        primelist.at(i)=0;
        break;
      }
      primelist.at(i)=1;
    }
  }
  
  while(cin >> n){
  
  sum=0;
  for(int i=0;i<(n+1);i++){
    sum=sum+primelist.at(i);
  }
  
  
  cout <<sum<<endl;
  }
  return 0;
}

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

using namespace std; 

int list[1000000]={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, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil,input,mid;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	lo=1087;
	a=180;
	while(lo<=1000003)
	{
		if(Prima(lo))
		{
			list[a]=lo;
			a++;
		}
		lo+=2;
	}
	//printf("%d",list[78498]);
	while(scanf("%ld",&input)!= EOF)
	{	
	lo=0;
	hi=78497;
	/*while(lo<=hi)
        {
            mid=(lo+hi)/2;
            if (list[mid]<input)
            {
                lo=mid+1; 
            } 
            else if(list[mid]>input)
            {
                hi=mid-1; 
            }
            else 
            {
                break; 
            } 
        }*/
	while(input>=list[lo])
	{
		lo++;
	}
	printf("%d\n",lo);
	}
	return 0; 
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		int i;
		bool number[1000000]={false};
		int ans=0;

		for(i=2;i<n;i++){
			if(number[i]==false){
				ans++;
				for(m=i;m<n;m+=i){
					number[m]=true;
				}
			}
		}
		cout<<ans<<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>
using namespace std;
int main()
{
	bool p[1000000] = { false };
	int n;
	for (int i = 2; i <1000000; i++){
		for (int i2 = 2; i*i2 <= 1000000; i2++){
				p[i*i2] = true;
			}
		}
		p[2] = false;
		p[3] = false;
	while (cin >> n){
		
		
		int c = 0;
		for (int i = 2; i <= n; i++){
			if (!p[i])c++;
		}
		cout << c << endl;
	}
}

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

int main(){
	int n;
	int a[10000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}