Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

#define Max 999999

int main(){
	bool is_prime[Max+1];
	for(int i=0;i<=Max;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=Max;i++){
		if(is_prime[i]){
			for(int j=i*2;j<=Max;j+=i)is_prime[j]=false;
		}
	}
	int n;
	while(std::cin>>n){
		int count=0;
		for(int i=2;i<=n;i++){
			if(is_prime[i])count++;
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	int n;
	cin >> n;
	
	vector <bool> p(n+1, true);
	p[0] = p[1] = false;
	for ( int i = 4; i < n; i += 2 )
	{
		p[i] = false;
	}
	for ( int i = 3; i <= n; i += 2 )
	{
		if ( p[i] )
		{
			cout << i << endl;
			for ( int j = i+i; j <= n; j += i )
			{
				p[j] = false;
			}
		}
	}

	int kotae = 1;
	for ( int i = 3; i < n; i += 2 )
	{
		if ( p[i] )
			kotae++;
	}

	cout << kotae << endl;

	return 0;
}

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

vector<int> sieve;

void make_prime(){
  bool a[1000001];
  for(int i = 0; i <= 1e6; i++)a[i] = false;
  a[0] = true;
  a[1] = true;
  for(int i = 2; i <= 1e6; i++){
    if(a[i])continue;
    sieve.push_back(i);
    for(int j = i; j <= 1e6; j += i){
      a[j] = true;
    }
  }
}

int main(){
  int n;
  make_prime();
  while(cin >> n){
    int cnt = 0;
    for(int i = 0; sieve[i] <= n; i++)cnt++;
    cout << cnt << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
using namespace std;
int main()
{
	    int n;
		bool a[1000001]; 
		memset(a,0,sizeof(a));
		for(int i=2;i<=1000;++i)
		{
			for(int j=2;j*i<=1000000;++j)
			{
				a[i*j]=1;
			}
		}

	while(cin>>n)
	{
		int count=0;
		for(int k=2;k<=n;k++)
		{
			if(!a[k])
			count++;
		}
		cout<<count<<endl;
	
	
		
	}
	return 0;
}

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

using namespace std;

int main()
{ 
	int n;
	while (cin >> n)
	{
		vector<bool> a(n + 1, true);
		int cnt = n == 0 ? 0 : n - 1;

		// Sieve of Eratosthenes
		for (int i = 2; i*i < n; ++i)
			if (a[i])
				for (int j = 0; i * (j + 2) <= n; ++j)
					if (a[i * (j + 2)]) a[i * (j + 2)] = false, cnt--;

		cout << cnt << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<ctype.h>
#include<math.h>
#include<map>
#include<time.h>
using namespace std;
const int N=1e6;
int isprime[N];
int prefixsum[N];
int SQRT=ceil(sqrt((double)N));		//返回大于或者等于指定表达式的最小整数 
int prime()
{
	memset(isprime,1,sizeof(isprime));
	int i;
	isprime[0]=isprime[1]=0;
	for(i=0;i<=SQRT;i++)
	{
		if(isprime[i])
		{
			for(int j=i*i;j<=N;j+=i)
			{
				isprime[j]=0;
			}
		}
	}
}
void maketable()
{
	for(int i=1;i<N;i++)
	{
		prefixsum[i]=isprime[i]?prefixsum[i-1]+1:prefixsum[i-1];
	}
} 
int main()
{
	prime();
	maketable();
//	printf("%.2f\n",(double)clock()/CLOCKS_PER_SEC);
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",prefixsum[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}

	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		int c = 0;
		if ( n == 2 )
			c = 1;
		else if( n < 2 )
			c = 0;
		else
		{
			c = 1;
			for ( int i = 3; i <= n; i += 2 )
			{
				if ( primes[i] )
					c++;
			}
		}

		cout << c << endl;

	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int a[1000000];
int sum[1000000];
int n;
int main(){
 for (int i=2;i<1000000;i++){
  if (!a[i])
   for (int j=i*2;j<1000000;j+=i)
    a[j]=1;
 }
 for (int i=2;i<1000000;i++) sum[i]=sum[i-1]+(a[i]==0?1:0);
 while (cin>>n)
  cout<<sum[n]<<endl;
 return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int mx = 1000010;
  vector<bool> isp(mx,true);
  isp[0]=false;
  isp[1]=false;
  REP(i,mx){
    if(isp[i]==false)continue;
    int t = i*2;
    while(t<mx){
      isp[t] = false;
      t += i;
    }
  }
  vector<int> sum(mx,0);
  REPR(i,mx) sum[i] = sum[i-1] + isp[i];
  int n;
  while(~scanf("%d",&n))cout<<sum[n]<<endl;
  return 0;
}

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

int main(void)
{
	bool prime[1000000];
	unsigned long n;

	for(unsigned long j = 2; j <= 999999; j++)
		prime[j] = true;
	for(int i = 2; i <= 1000; i++) {
		if(prime[i] == true) {
			for(unsigned long j = i * i; j <= 999999; j += i) {
				prime[j] = false;
			}
		}
	}

	while(cin >> n) {
		unsigned cnt = 0;
		for(unsigned long j = 2; j <= n; j++) {
			if(prime[j] == true) {
				cnt++;
			}
		}

		cout << cnt << endl;
	}
	return 0;
}

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

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	int n; while(cin >> n){
		int sum = 0;
		for (int i = 1; i < n + 1; i++) {
			if (isprime(i))sum++;
		}
		cout << sum << '\n';
	}
	return 0;
}

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

bool isPrime(int a){
	int x = std::sqrt((double)a);
	for(;x>1;x--)
		if(a%x == 0)
			return false;
	return true;
}

int countPrime(int a){
	int x = a,ans = 1;
	if(x%2==0)
		x--;
	for(; x>1; x-=2)
		if(isPrime(x))
			ans++;
	return ans;
}

int main(){
	int n;
	while(std::cin >> n)
		std::cout << countPrime(n) << std::endl;
	return 0;
}

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

int p[1000010];

int main(){
	int n;
	int count;

	//エラトステネスの篩
	//素数のリストをつくる
	for (int i = 0; i <= 1000000; i++) p[i] = 1;
	p[0] = p[1] = 0;
	for (int i = 2; i*i <= 1000000; i++){
		if (p[i] == 1){
			for (int j = 2; i*j <= 1000000; j++){
				p[i*j] = 0;
			}
		}
	}

	//素数のカウント
	while (cin >> n){
		count = 0;
		for (int i = 0; i <= n; i++){
			if (p[i] == 1)count++;
		}
		cout << count << endl;
	}

	return 0;
}