Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,sum;
    int b[999999];
    b[0]=0;
    for(int i=1;i<999999;i++){
        b[i]=prime(i);
    }
    while ( cin >> a){
        sum =0;
        for (int i=1;i<a;i++){
            sum +=b[i+1];
        }
        cout << sum << endl;
    }
}


int prime(int x){
    if(x==1)
        return 0;
    if(x==2 || x==3 || x==5 || x==7)
        return 1;
    if(x%2==0 || x%3==0)
        return 0;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 0;
    }
    return 1;
}

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

using namespace std; 

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

bool Prima(unsigned long n) 
{
    if (n % 2 == 0 || n % 3 == 0)
	{
        return false;
    }
 
    for (unsigned short i = 5; i * i <= n; i += 6) 
	{
        if (n % i == 0 || n % (i + 2) == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	while(scanf("%ld",&hi)!= EOF)
	{
	lo=2;
	hasil=1;
		while(lo<=hi)
		{
			if(lo==2||lo==3||lo==5)
			{
				hasil++;
				lo=lo+1; 
			}
			if(lo==4)
			{
				lo++;
			}
			else 
			{
				if(Prima(lo))
				{
					hasil++;
				}
				lo++;
			}
		}
	printf("%d\n",hasil);
	}
	return 0; 
}

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

int get_num_of_under_n(int n) {
	bool* numbers = new bool[n + 1];
	for (int i = 2; i < n + 1; i++) {
		numbers[i] = true;
	}
	for (int i = 2; i < sqrt(n); i++) {
		if (numbers[i] == true) {
			for (int j = 0; i*(j + 2) <= n; j++) {
				numbers[i*(j + 2)] = false;
			}
		}
	}
	int ans = 0;
	for (int i = 2; i < n + 1; i++) {
		if (numbers[i] == true)ans++;
	}
	return ans;
}
int main() {
	int n;
	while (cin>>n) {
		cout << get_num_of_under_n(n)<<endl;
	}
}

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

int main(){
 int n,i,j,x,counter;
 cin >> n;
 counter = 0;
 
 for (i = 1; i <= n; i++) {
   x = 0;
   
   for (j = 1; j <= i; j++) {
     if (i % j == 0) x++;
   }
   
   if (x == 2) counter++;
 }
 
 cout << counter << endl;
 
 return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main (void)
{
	long a[10000],co = 3;

	a[0] = 2;
	a[1] = 3;
	a[2] = 5;
	a[3] = 7;
	for (long long i = 8; i < 100000; i++)
	{
		if (i % 2 != 0 && i % 3 != 0)
		{
			if (i % 5 != 0 && i % 7 != 0)
			{
				co += 1;
				a[co] = i;
			}
		}
	}

	long long n,co2;

	while (cin >> n)
	{
		co2 = 0;
		for (long j = 0; j < co + 1; j++)
		{
			if (a[j] > n)
			{
				break;
			}
			co2 += 1;
		}

		cout << co2 << endl;
	}
}

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

int main(){
	int m=0,n;
	cin>>n;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(n);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
	return 0;
}

C++: #include<bits/stdc++.h>
#define ll long long
#define pi acos(-1)
#define MAXN 1000010
#define inf 0x3f3f3f3f
using namespace std;
typedef pair<int,int>P;
bool prime[MAXN];
int cnt[MAXN];
void init()
{
	memset(prime, true, sizeof(prime));
	prime[1] = false;
	for(int i = 2; i < MAXN; i++)
	{
		if(prime[i])
		for(int j = i * 2; j < MAXN; j += i)
		prime[j] = false;
	}
	for(int i = 1; i < MAXN; i++)
	if(prime[i])
	cnt[i] = cnt[i - 1] + 1;
	else
	cnt[i] = cnt[i - 1];
}
int main()
{
	int n;
	init(); 
	while( cin >> n)
	{
		cout << cnt[n] << endl;
	}
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    int a[n];
    for(int i=0;i<n;i++){
      a[i]=1;        //1 素数　０素数ではない
    }
    a[0]=0;
    cont=0;
    for(int i=2;i<=sqrt(n);i++){
      if(a[i-1]==1){
	for(int j=2;i*j<=n;j++){
	  a[i*j-1]=0;
	}
      }
    }
    for(int i=0;i<n;i++){
      if(a[i]==1)cont++;
    }
    cout<<cont<<endl;
  }
}

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

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

int main() {
    int dp[1000100] = {0};
    for (int i = 2; i <= 1000000; i++) {
        if (isPrime(i)) dp[i] = dp[i - 1] + 1;
        else dp[i] = dp[i - 1];
    }

    int n;
    while (cin >> n) cout << dp[n] << endl;
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define len 200000
int prime[len];
int a; 
bool mark[len];

void f()
{
    a=0;
    long long int i,j;
    for( i=0; i<len; i++)
    {
        mark[i]=false;
    }
    for( i=2; i<len; i++)
    {
        if(mark[i]==true)  
            continue;
        else
        {
            prime[a++]=i;
            for( j=i*i; j<len; j+=i)
            {
                mark[j]=true;
            }
        }
    }
}
int main()
{
    f();
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",prime[n-1]);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int *p=upper_bound(prime,prime+num,n);
        cout<<"*"<<*p<<endl;
        int ans=p-prime;
        cout<<ans<<endl;
    }
    return 0;
}

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

	bool is_prime[1000000];
	int n_prime[1000000];
int main()
{
	
	is_prime[0]=is_prime[1]=false;
	for(int i=0; i<1000000; i++){
		is_prime[i]=true;
	}
	
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<1000000; j+=i){
				is_prime[j]=false;
			}
		}
	}


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

		int n;
		cin>>n;

	
		cout<<n_prime[n]<<endl;
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX (1000000)
int main(){
  vector<bool> isP(MAX,true);
  vector<int>  ans(MAX,0);
  int n;
  isP[0] = isP[1] = false;
  for(int i=2; i<MAX; i++)
    if(isP[i]){
      ans[i] = ans[i-1] + 1; 
      for(int j=i+i; j<MAX; j+=i)
	isP[j] = false;
    }else{
      ans[i] = ans[i-1];
    }
  
  while(cin>>n) cout<<ans[n]<<endl;
  return 0;
}