Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <iostream>

using namespace std;
int ns[1000000];
int main()
{
    int n;
    while(cin>>n)
    {
        fill(ns,ns+1000000,true);
        ns[1]=false;
        int cnt=0;
        for(int i=2;i<=n;++i){
            if(ns[i])cnt++;
            for(int j=0;j*i<=n;++j){
                ns[i*j]=false;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<'\n';}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;tag:m[i]=e;}}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 100000
int p[MAX+1];
void f(){
	int n=0;
	for(int i=2;i<=MAX;i++){
		if(p[i]==0){
			p[i] = ++n;
			for(int j=2;j*i<=MAX;j++)
				p[j*i] = -1;
		}
		else p[i] = n;
	}
} 
int main(){
	int n;
	f();
	while(cin>>n){	
		cout<<p[n]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main()
{
	bool *sosu;
	int *ans,now,n;

	sosu = new bool[1000000];
	ans = new int[1000000];

	for(int i = 0; i < 1000000; i++){
		sosu[i] = true;
	}
	sosu[0] = sosu[1] = false;
	for(int i = 0; i < 1000000; i++){
		if(sosu[i] == true){
			for(int j = 2; j*i < 1000000; j++){
				sosu[j*i] = false;
			}
		}
	}
	now = 0;
	for(int i = 0; i < 1000000; i++){
		if(sosu[i] == true)
			now++;
		ans[i] = now;
	}

	while(scanf("%d",&n) != EOF){
		printf("%d\n",ans[n]);
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

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

signed main(){
  int n;
  while(cin>>n&&n){
    if(n==1){cout<<0<<en; RE;}
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)) ans++;
    }
    cout<<ans<<en;
  }
}

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

bool is_SPRP(uint32_t n, uint32_t a) {
  uint32_t d = n - 1, s = 0;
  while ((d & 1) == 0) {
    ++s;
    d >>= 1;
  }
  uint64_t cur = 1, pw = d;
  while (pw) {
    if (pw & 1) {
      cur = (cur * a) % n;
    }
    a = ((uint64_t)a * a) % n;
    pw >>= 1;
  }
  if (cur == 1) {
    return true;
  }
  for (uint32_t r = 0; r < s; r++) {
    if (cur == n - 1) {
      return true;
    }
    cur = (cur * cur) % n;
  }
  return false;
}

bool is_prime(uint32_t x) {
  if (x <= 1) return false;
  if (x < 1ULL << 32) {
    uint32_t bases[] = {2, 7, 61};
    for (uint32_t i = 0; i < sizeof(bases) / sizeof(bases[0]); ++i) {
      if (x != bases[i] && !is_SPRP(x, bases[i])) {
        return false;
      }
    }
    return true;
  }
}

int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (is_prime(i)) ans++;
    }
    cout << ans << endl;
  }
}

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

int main() {
int b[1000000];
for (int k=0;k<1000001;k++){
	b[k]=0;
}
for (int p=2;p<1000001;p++){
int i,a=0 ;
	i=2;
	while(i<p){
		if(p%i==0){
			break;
	}i=i+1;
	}
	if (i==p){
		a=1;
	}
	b[p]=a;
}
int c[1000000];
for (int l=0;l<1000001;l++){
	c[l+1]=c[l]+b[l+1];
}
int r;
while(cin>>r){
	cout<<c[r]<<endl;
}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
// have you mooed today?
bool isprime(int& num)
{
    static int c;
    static int max;
    if(num == 1) return false;
    if(num == 2) return true;
    if(num % 2 == 0) return false;
    max = ceil(sqrt(num));

    for(c=3; c < max+1; c+=2)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans =0;
    int c;
    int buff;
    vector<int> prime;
    for(c=1;c<=999999;c++)
    {
        if(isprime(c)) ans++;
        prime.push_back(ans);
    }
    cout << prime[0] << endl;
    while(cin >> buff)
    {
        cout << prime[buff -1] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
bool flg[1000000];
int main(void){
	int n;
	int i,j;
	int cnt=0;
	while(1){
		cin>>n;
		if(cin.eof())	break;
		fill(flg,flg+n+1,0);
		for(i=2;i*i<=n;i++){
			//cout<<"I="<<i<<endl;
			for(j=2;i*j<=n;j++){
				//cout<<"J="<<j<<endl;
				flg[i*j]=1;
			}
		}
		cnt=0;
		for(i=2;i<=n;i++)	if(flg[i]==0)	cnt++;
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
int fact(int x){
	int sx=0,sy=0;
	for(int i=2;i<x+1;i++){
		if(x%i==0)sx++,sy+=i;
	}
	if(sx==1)return x;
	else return sy+1;
}
int main(){
	int a=0;
	while(std::cin>>a){
		int n=0;
		for(int i=2;i<a+1;i++){
			if(i==fact(i))n++;
		}
		std::cout<<n<<std::endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int N;
	int count;

	while(cin>>N)
	{
		count=0;
		for(int i=2;i<=N;i++)
		{
			int f=0;
			for(int j=1;j<i;j++)
				if((i%j)==0)
					f++;
			if(f<2)count++;
		}

		cout<<count<<endl;
	}

	return 0;
}

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

using namespace std;

int sosuu(int n);

int main(){
    int n=0;
    int num=0;
    int a[30][2]={0};
    int max=0;
    while(scanf("%d",&n)!=EOF){
        if(max<n){
            max=n;
        }
        a[num][0]=n;
        num++;
    }
    
    int b[max];
    for(int i=0; i<=max; i++){
        b[i]=i;
    }
    b[1]=0;
    
    for(int i=2; i<sqrt(max); i++){
        for(int j=i+1; j<=max; j++){
            if(j%i==0){
                b[j]=0;
            }
        }
    }
    
    
//    for(int j=0; j<num; j++){
//        cout<<a[j][0]<<"\n";
//    }
//    
//    for(int j=0; j<=max; j++){
//        cout<<b[j]<<"\n";
//    }
    
    
    
    for(int i=0; i<num; i++){
        for(int j=0; j<=a[i][0]; j++){
            if(b[j]!=0){
                a[i][1]++;
            }
        }
    }

    
    for(int j=0; j<num; j++){
        cout<<a[j][1]<<"\n";
    }
    
}

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

using namespace std;

long long int n,i;
int a[1000001] = {0};
int ans;

int main()
{
    for(int i = 2; i < 1000000; i++)
    {
        if(a[i] == 0)
        {
            for(int j = 2; i * j <= 1000000; j++)
            {
                a[i * j] = 1;
            }
        }
    }
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            if(a[i] == 0)ans++;
        }

        /*for(int i = 2; i <= n; i++)
        {
            if(i == 2 || i == 3 ||  i == 5 || i == 7)ans++;

        }*/
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}