Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

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

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

		for(i=0;i<n;i++){
			if(number[i]==0){
				ans++;
				for(m=i;m<n;m+=i){
					number[i]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=999999+10;
int n,cnt,t;
int pre[maxn],prime[maxn];
int get(int x){
	int l=0,r=t-1,mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(prime[mid]>=x)
			r=mid+1;
		else
			l=mid+1;
	}
	return r;
}
int main(){
	memset(pre,0,sizeof(pre));
	memset(prime,0,sizeof(prime));
	t=1;
	for(int i=2;i<maxn;i++){
		if(!pre[i])
			prime[t++]=i;
		for(int j=1;j<=t&&i*prime[j]<maxn;j++){
			pre[prime[j]*i]=prime[j];
			if(i%prime[j]==0)
				break;
		}
	}
	while(cin>>n){
		int ans=0;
		while(prime[ans]<=n)
			ans++;
		cout<<ans-1<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool IsPrime(int n)
{
	int s = floor(sqrt(n)+0.5);
	for(int i = 2;i<=s;i++)
		if(n%i==0)return false;
	return true;
}
const int maxn = 1000000;
bool ar[maxn];
int dp[maxn];
int main()
{
	for(int i = 2;i<=maxn;i++)
		if(IsPrime(i))
		{
			ar[i] = true;
			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>
using namespace std;


int main() {

	int judge[1000000];
	for(int k=0;k<1000000;k++)judge[k]=1;
	int n,sum;
	
	while(cin>>n){
		if(n==0||n==1){
			sum = 0;
		}else{
			sum = 1;
			for(int i=3;i<n+1;i+=2){
				if (judge[i]==1){
					sum++;
					for(int j=2;j<=n/i;j++)
						judge[i*j] = 0;
				}	
			}
		}
		
		cout << sum <<endl;
	}

	return 0;
}

C++: #include&<iostream>
#include&<vector>
using namespace std;
int main(){
    int n,k,sum,check;
    int t=1;
    vector<int> prime;
    prime.push_back(0);
    prime.push_back(0);
    for(int i=2;i<1000000;i++){
        prime.push_back(1);
    }
    while(t<1000000){
        for(int j=t+1;j<=1000000;j++){
            if(prime[j]==1){
                t=j;
                for(k=2*j;k<=1000000;k+=j){
                    prime[k]=0;
                }
                break;
            }
            else if(j==1000000){
                t=1000000;
            }
        }
    }
    while(cin>>n){
        sum=0;
        for(check=1;check<=n;check++){
            if(prime[check]==1){
                sum+=1;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++: j,a['   '],s;main(i){for(;++i<1e6||~scanf(s="%d\n",&j)&&printf(s,a[j]);)for(a[i]=s+=!a[j=i];j<1e6;a[j+=i]=1);}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

bool prime[1000000];
int ans[1000000];

void is_prime(){
  rep(i,1000000)prime[i]=true;
  prime[0]=prime[1]=false;
  REP(i,2,1000000){
    if(prime[i]==true){
      for(int j=i+i;j<1000000;j+=i)prime[j]=false;
    }
  }
  if(debug)rep(i,1000)if(prime[i])cout<<i<<endl;
}

void calc(){
  ans[0]=0;
  REP(i,1,1000000){
    ans[i]=ans[i-1]+prime[i];
  }
}

int main(){
  int n;
  is_prime();
  calc();
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 1000005
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
#define ll long long
typedef pair<int, int> P;

bool prime[MAX_N];

void solve()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	FOR(i, 2,(int)sqrt(MAX_N))
	{
		if (prime[i] == true)
		{
			for (int j = 2; j*i <= 1000000; j++){
				if (prime[i*j] == true)prime[i*j] = false;
			}
		}
	}
}

int main()
{
	int n;
	while (cin >> n)
	{

		int ans = 0;

		solve();
		REP(i, n + 1){
			if (prime[i] == true){
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int isPrime(int n) {
	if (n == 2) {
		return 1;
	}
	if ((n <2) || (n % 2 == 0)) {
		return 0;
	}
	int i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0) {
			return 0;
			
		}
		i += 2;
	}
	return 1;
}
int main()
{
	int x[30];
	int i = 0;
	while (cin >> x[i]) {
		int k = 0;
		for (int j = 0; j < x[i]; j++) {
			
			k += isPrime(j+1);
		}
		cout << k << endl;

		i++;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[999999]={0,0,1,2},n,k=1,count=2;
	for(int i=4;i<999999;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){k++;break;}
		}
		if(k==0)count++;
		a[i]=count;
		k=1;
	}
	while(cin>>n)cout<<a[n]<<endl;
	return 0;
}

C++: 
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		while(true){
			Scanner sc=new Scanner(System.in);
			int INF=1000;
			int cnt=0;
			int n=sc.nextInt();
			int[] prime=new int[n+1];
			for(int i=0;i<=n;i++){
				prime[i]=INF;
			}
			for(int i=2;i<=n;i++){
				if(prime[i]==INF&&n%i==0){
					prime[i]=0;
					cnt++;
					for(int j=2;j*i<=n;j++){
						prime[j*i]=1;
					}
				}
			}
sc.close();
			System.out.println(cnt);
		}
	}
}

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

int a[1000000];

int main()
{
  int n;
  int count;

  for (int i = 2; i < 1000000; i++){
     a[i] = 1;
   }

   for (int i = 0; i * i < 1000000; i++){
     if  (a[i] == 1){
       for (int j = 2; j * i <= 100000; j++){
         a[j * i] = 0;
       }
     }
   }

   while (cin >> n){
     count = 0;
     for (int i = 0; i < 1000000; i++){
       if (a[i] == 1){
         count++;
       }
     }
   }

   cout << n << endl;

   return (1);
}

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

int arr[1000000];

void ar()
{
	int cnt;
	arr[2] = 1;
	int j;
	int i = 3;
	for (; i < 1000000; ++i) {
		cnt = 1;
		for (j = 2; j < i; ++j) {
			if (i%j == 0) {
				arr[i] = arr[i - 1];
				--cnt;
				break;
			}
		}
		arr[i] = arr[i - 1] + cnt;
	}
}

int main()
{
	int x;
	ar();
	while (cin >> x) {
		cout << arr[x] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
const int size=1000000;
int main(){
  int i,k,n;
  int data[size];
  int sum[size];
  for(i=2;i<size;i++){
    data[i]=1;
  }
  for(i=2;i<size;i++){
    if(data[i]){
      for(k=2*i;k<=size;k+=i){
        data[k]=0;
      }
    }
  }
  for(i=2;i<size;i++){
    sum[i+1]=sum[i]+data[i];
  }
  while(scanf("%d",&n)!=EOF){
    printf("%d\n",sum[n+1]);
  }
}

C++: import math
import sys

def prime_calc(n):
    rootN = math.floor(math.sqrt(n))
    prime = [2]
    data = [i + 1 for i in range(2,n,2)]
    while True:
        p = data[0]
        if rootN < p:
            return len(prime + data)
        prime.append(p)
        data = [e for e in data if e % p != 0]

def main():
    l = []

    for line in sys.stdin:
        l.append(line)        

    for line in l:
        print(prime_calc(line))

if __name__ == "__main__":
    main()