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<stdio.h>

int main(void){

	int sosuu[100000],kazu,n,i,j;

	while(scanf("%d",&n)!=EOF){
		kazu=n-1;
		for(i=2;i<=n;i++){
			sosuu[i]=1;
		}
		for(i=2;i<=n;i++){
			if(sosuu[i]==1){
				for(j=i*2;j<=n;j+=i){
					if(sosuu[j]==1){
						kazu--;
						sosuu[j]=0;
					}
				}
			}
		}
		printf("%d\n",kazu);
		
	}

	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
#define MAX 1000000

bool prime[MAX]={};

void run(){
  for(int i=2;i<MAX;i++){
    prime[i]=true;
  } 

  for(int i=2;i<MAX;i++){
    if(!prime[i])continue;
    for(int j=2;j*i<MAX;j++){//i*1 is prime number
      prime[i*j]=false;
    }
  }
  return;
}

int main(){

  run();
  
  int n;
  while(cin>>n){
    int sum=0;
    for(int i=2; i<=n; i++){
      if(prime[i])sum++;
    }
    cout<<sum<<endl;
  }
  return 0;

}

C++: #include<stdio.h>

int main()
{
	int n,m;
	while(scanf("%d",&n) !=EOF)
	{
		m=0;
		for(int x=2;x<=n;x++)
		{
			for(int y=x-1;y;y--)
			{
				if(y==1)
				{
					m++;
				}
				else if(x%y==0)
				{
					break;
				}				
			}
		}
		printf("%d\n",m);
	}
}

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

using namespace std;

int main()
{
	vector<int>D(1000000 , 1);
	D[0] = 0;
	D[1] = 0;
	for(size_t i = 2; i <= sqrtl(1000000); i++)
	{
		if(D[i])
		{
			int j = 2;
			while(i*j < 1000000)
			{
				D[i*j] = 0;
				j++;
			}
		}
		D[i] += D[i - 1];
	}
	int n;
	while(cin >> n)cout << D[n] << endl;
	return 0;
}

C++: #include <stdio.h>
#include <string>
#include <iostream>

//using namespace std;

int sosuu(int n);

int main(){
    int n = 0;
    
    while(scanf("%d",&n)!=EOF){
        int temp = 0;
        if(n==1){
            printf("%d",0);
        }else{
            for(int i=2; i<=n; i++ ){
                temp+=sosuu(i);
                if(i!=2){
                    i++;
                }
            }
            printf("%d\n",temp);
        }
    }
    
    
}

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

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

int main(){
    int n, cnt;
    bool prime[1000000];
    prime[0] = prime[1] = false;
    
    for(int i = 2;i < 100000;i++){
        if(i%2 == 0){
            prime[i] = false;
        }else{
            prime[i] = true;
        }
    }

    while(cin >> n){
        cnt = 0;
        
        for(int i = 2;i <= sqrt(n);i++){
            if(prime[i]){
                for(int j = 2*i;j<= n;j++){
                    if(j%i == 0){
                        prime[j] = false;
                    }
                }
            }
        }
        
        for(int i = 2;i <= n;i++){
            if(prime[i]){
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
int ans[1000000];

int main(){
  for(int i=2;i<=999999;i++){
    ans[i]=ans[i-1];
    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0)goto f;
    }
    ans[i]++;
    f:;
  }
  while(cin>>n){
    cout<<ans[n]<<endl;
  }

  return 0;
}

C++: //#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

bool isprime[1000000];
int ans[1000000];

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	rep(i, 0, 1000000)isprime[i] = true;
	isprime[0] = false;
	isprime[1] = false;
	ans[0] = ans[1] = 0;
	int n = 0;
	rep(i, 2, sqrt(1000000))
	{
		if (isprime[i])
		{
			n++;
			for (int j = 2 * i; j < 1000000; j += i)
			{
				isprime[j] = false;
			}
		}
		ans[i] = n;
	}

	int N;
	while (cin >> N)
	{
		cout << ans[N] << endl;
	}

	return 0;
}

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

int prime(int n){
  long long cnt=0,prime[n];
  bool f[n+1];
  for(int i=0;i<=n;i++){
    f[i]=true;
  }
  f[0]=f[1]=false;
  for(int i=2;i<=n;i++){
    if(f[i]){
      prime[cnt++]=i;
      for(int j=2*i;j<=n;j+=i){
        f[j]=false;
      }
    }
  }
  return cnt;
}

int main(){
  long long n;
  while(cin >> n){
    cout << prime(n) << endl;
  }
  return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int count;
	c[0]=c[1]=0;
	for(i=2;i<100000;i++){
		c[i]=1;
	}

	while(scanf("%d",&n)!=EOF){

		count=0;

		
		for(i=2;i<=n;i++){
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0){
						c[j]=0;
					}
				}
				count++;
			}
		}

		printf("%d",count);


	}





	return 0;
}

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

int main()
{
	
	long int k,p[100000];
	float n;
	p[0]=2;
	while(cin>>n){
		if(n<0){
			break;
		}
	k=0;
	int r=(int)sqrt(n);
	for(int i=3;i<=r;i++){
		for(int j=0;j<k+1;j++){
			if(i%p[j]==0){
				break;
			}else if(j==k){
				k++;
				p[k]=i;
			}
		}
	}
	int r_k=k;
	for(;r<n;r++){
		for(int i=0;i<=r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k){
				k++;
			}
		}
	}
	if(k!=0&&k!=1){
	cout<<k+1<<endl;
	}else{
		cout<<k<<endl;
	}
	}
}

C++: #include<iostream>

using namespace std;

int main()
{
    long int n;
    int i,k,j,b=0;

    cin >> n;
    if(1<=n<=999999)
    {
        for(i=2; i<=n; i++)
    {
        k = 1;
        for(j=2; j<=i/2; j++)
        {
            if(i%j==0)
            {
                k = 0;
                break;
            }
        }

        if(k==1)
        {
            b++;
        }
    }
    }

    cout << b << endl;

    return 0;

}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
//	vector<int> isPrime;
	bool isPrime[1000000];
	
	while(cin>>n)
	{
		for(int i = 0; i < n; i++){
//			isPrime.push_back(1);
			isPrime[i] = 1;
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
//			printf("head:%d    fin:%d\n",head,fin);
			
			if(fin < head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
			}
		}
		printf("%d\n",cont);
	}
}