Go: package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	//"math"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		fmt.Println(calc(n))
	}
}

func calc(n int)int{
	// エラトステネスで数え上げる
	// 最初から999999まで用意しておいて入力のたびO(1)で出すのとどっちが速いのかはわからん
	eratos := make([]bool, n+1)
	c := 0
	for i:=2; i<len(eratos); i++{
		if eratos[i] == false{
			c++
			for j:=i*i; j<len(eratos); j+=i{
				eratos[j]=true
			}
		}
	}
	return c
}

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

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

C++: #include<iostream>

using namespace std;

int main(void){
	
	long int n,f,k,i;
	bool chk;
	while(cin>>n){

		for(i=2;i<=n;i++){
		
			chk=0;
			f=i/2;
			k=2;
		
			while(f>=k){
				if((i%k)==0){
					chk=true;
					break;
				}
				k++;
			}
		
			if(chk==false){
				cout<<i<<endl;
			}
		}
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;

int main(void){
    int n,i,j,sosu[999999],ans=0;
    for(i=0;i<999999;i++) sosu[i]=1;
    sosu[0]=0;
    for(i=2;i<=999999;i++){
        if(sosu[i-1]==1){
            for(j=i*2;j<=999999;j+=i){
                sosu[j-1]=0;
            }
        }
    }
    while(cin >> n){
        ans=0;
        for(i=0;i<n;i++){
            ans+=sosu[i];
        }
        cout << ans << endl;
    }
    return 0;
}

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

bool arr[1000000] = {};

void sieve(){
	for(int i = 2; i < 1000000; i++){
		if(arr[i])
			continue;
		for(int j = i*2; j < 1000000; j+=i)
			arr[j] = true;
	}
}

int check(int n){
	int counter = 0;
	for(int i = 2; i <= n; i++)
		if(!arr[i])
			counter++;
	return counter;
}

int main(){
	sieve();
	int a;
	while(cin >> a){
		cout << check(a) << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstudio>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


const int Max=10000000;
bool prime[Max];
int main(void){
    int in;
    for(int i=0;i<Max;i++)prime[i]=true;
    prime[1]=false;
    for(int i=2;i<Max;i++){
        if(prime[i]){
            for(int s=i*2;s<=Max;s+=i)prime[s]=false;
        }
    }
    while(cin>>in){
        int cnt=0;
        for(int i=1;i<=in;i++){
            if(prime[i])cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include <sstream>
using namespace std;
int main(void){
    int n,ans,i;
    while(cin >> n){
        ans = 0;
        if(n < 2){
            cout << 0;
            continue;
        }else if(n == 2){
            cout << 1;
        }else{
            ans++;
        }
        for(i = 3; i <= n; i += 2){
            double sqrti = sqrt(i);
            if(ceil(sqrti) == floor(sqrti)){
                continue;
            }
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

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

int main(){

  int n;
  while(scanf("%d",&n)!=EOF){
    int cnt=0;
    for(int i=1;i<=n;i++)
      if(isPrime(i)==true) cnt++;
    printf("%d\n",cnt);
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1000000;
int prime[MAXN + 1];
void getPrime()
{
    memset(prime, 0, sizeof(prime));
    for (int i = 2; i <= MAXN; i++)
    {
        if (!prime[i])
        {
            prime[++prime[0]] = i;
        }
        for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++)
        {
            prime[prime[j] * i] = 1;
            if (i % prime[j] == 0)
            {
                break;
            }
        }
    }
}
int main()
{
	getPrime();
	int n,sum;
	while(~scanf("%d",&n)){
		sum=0;
		for(int i=1;i<MAXN;i++){
			if(prime[i]<=n){
				sum++;
			}else{
				break;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int i,j,ch[1000000];

    for(i=0;i<1000000;i+=2){ch[i]=0;ch[i+1]=1;}

    ch[1]=0;
    ch[2]=1;

    for(i=3;i<1000;i+=2) if(ch[i]) for(j=i<<1;j<1000000;j+=i) ch[j]=0;

    for(i=3;i<1000000;i++) ch[i]+=ch[i-1];

    while(cin>>i) cout<<ch[i]<<endl;

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
const int N=1e6+10;
bool prime[N];
int ans[N];
void init()
{
    prime[0]=prime[1]=false;
    for(int i=2; i<=N; i++)
        prime[i]=true;
    int cnt=0;
    for(int i=2; i<=N; i++)
    {
        if(prime[i])
        {
            cnt++;
            for(int j=2*i; j<=N; j+=i)
                prime[j]=false;
        }
        ans[i]=cnt;
    }
}
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    init();
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",ans[n]);
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <ctime>
 
using namespace std;
 
int main()
{
    int n;
    vector<int> prime;
     
    //unsigned long t = time(NULL);
    prime.push_back(2);
	prime.push_back(3);
    while (scanf("%d", &n) != EOF){
		if (prime[prime.size() - 1] <= n){
			for (int i = prime[prime.size() - 1] + 2; i <= n; i += 2){
				bool p = true;
				for (int j = 0; prime[j] <= i / 2; j++){
					if (i % prime[j] == 0){
						p = false;
						break;
					}
				}
				if (p){
					prime.push_back(i);
				}
			}
		}
		
		int count;
		for (count = 0; count < prime.size() && prime[count] <= n; count++){
			;
		}
		printf("%d\n", count);
    }
     
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool array[1000500];
		for(int i=0;i<=n;i++){
			array[i]=true;
		}

		int count=0;
		array[0]=array[1]=false;
		for(int i=1;i<=n;i++){
			if(array[i]){
				count++;
				for(int j=i*2;j<=n;j+=i){
					array[j]=false;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include<stdio.h>



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

	while((scanf("%d",&n)!=EOF)&&(n!=0)){
		/*if(n>maxin){
			maxin=n;
		}*/
		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;
}