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 n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for(int a = 3;a<1000000;a++)
	{
		prime[a] = 1;
	}
	
	for(int a = 3;a<1000;a++)
	{
		if(checked[a] == 0)
		{
			checked[a] = 1;
			for(int b = 2;b<a;b++)
			{
				if(a%b==0)
				{
					prime[a] = 0;
					break;
				}
			}
			if(prime[a] == 1)
			{
				for(int c = 2*a ;c<1000000;c+=a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for(int a = 3;a<100;a++)
	{
		primesum[a] = primesum[a-1]+=prime[a];
	}
	
	while(cin >> n)
	{
		cout << primesum[n-1] << endl;
	}

	return 0;
}

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

#define Max 1000000

int isPrime[Max];

int main(){
    long num;
    long i,j;

    //配列の初期化
    isPrime[0] = isPrime[1] = 0;
    for(i = 2; i < Max; ++i){
        isPrime[i] = 1;
    }

    for(i = 2; i < Max; i++){
        if(isPrime[i] == 1){
            if(i % 2 == 0){
                isPrime[i] = 0;
            }else if(i % 3 == 0){
                isPrime[i] = 0;
            }else if(i % 5 == 0){
                isPrime[i] = 0;
            }else if(i % 7 == 0){
                isPrime[i] = 0;
            }
        }
    }

    isPrime[2] = 1;isPrime[3] = 1;isPrime[5] = 1;isPrime[7] = 1;

    while(cin >> num){
        long count = 0;
        for(i = 2; i <= num; ++i){
            if(isPrime[i] == 1){
                count++;
            }
        }
        cout << count << endl;
    }
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int n,cnt=0;
	while(cin >> n){
		for(int i=1;i<=n;i+=2){
			int k=0;
			for(int j=3;j<=(int)sqrt((double)i);j+=2){
				if(i%j==0){
					k=1;
					break;
				}
			}
			if(k==0){
				cnt++;
			}
		}
		cout << cnt << endl;
		cnt=0;
	}
}

C++: 
int main(void)
{
	int d=2,i,j,s[10000],x;

	while(scanf("%d",d)!=EOF)
	{
		for(i=0;i<=d;i++){
			s[i]=1;}
		x=0;
		if(d<=1){
			printf("%d\n",0);}
		else
		{
			for(i=2;i<=d/2;i++){
			  if(s[i]!=0){
				for(j=i*2;j<d;j+=i)
				    s[j]=0;
			  }
			}
		for(i=0;i<d;i++)
			x+=s[i];
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include <iostream>

using namespace std;

const int iMAX = 1000000;
const int iMAX_half = 500000;
int isPrime[iMAX];

int main()
{
	int n, cnt, sqSize;
	bool prime[iMAX_half];

	cnt = 1;
	sqSize = 1000;
	prime[0] = prime[1] = 0; prime[2] = 1;
	for(int i=3; i < iMAX; i+=2) prime[(i-1)>>1] = 1;
	for(int i=3; i < sqSize; i+=2) {
		if(prime[(i-1)>>1]) {
			for(int j=i+i+i; j < iMAX; j+=(i*2))
				if(j & 1) prime[(j-1)>>1] = 0;
		}
	}
	isPrime[0] = isPrime[1] = 0; isPrime[2] = 1;
	for(int i=3; i < iMAX; i+=2) {
		if(prime[(i-1)>>1]) cnt++;
		isPrime[(i-1)>>1] = cnt;
	}
	while(cin >> n)
	{
		if(n == 2)
			cout << 1 << endl;
		else
			cout << isPrime[(n-1)>>1] << endl;
	}

	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};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long 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){
    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<iostream>
using namespace std;

bool IsPrime(int m){
    if(m==1){
        return(1);
    }else if(m==2){
        return(1);
    }else if(m%2==0){
        return(0);
    }else{
        for(int i=3;i*i<=m;i+=2){
            if(m%i==0)return(0);
        }
        return(1);
    }
}
int main(){
    int n;
    int r[30];
    for(int i=0;i<30;i++){
        r[i]=0;
    }
    int j=0;
    while((char)n!=' '){
        cin>>n;
        for(int i=1;i<=n;i++){
            if(IsPrime(i))r[j]++;
        }
        cout<<r[j]<<endl;
        j++;
    }
    return(0);
}