Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

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

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
using ppa = pair<pa,int>;
#define SORT(v, n) sort(v, v+n);
#define ALL(v) v.begin(),v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v),greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

//4??????
//int dy[]={0, 1, 0, -1};
//int dx[]={1, 0, -1, 0};

//8??????
//int dy[]={0,0,1,-1,1,1,-1,-1};
//int dx[]={1,-1,0,0,1,-1,1,-1};

const ll MOD = 1000000007;

ll pow_mod(ll a,ll b,ll mod){
    ll tmp = 1;
    a %= mod;
    if(b > 0){
        tmp = pow_mod(a, b/2, mod);
        if(b % 2) tmp = (((tmp*tmp)%mod)*a)%mod;
        else tmp = (tmp*tmp)%mod;
    }
    return tmp;
}

int mm = 999999+1;
vector<bool> d(mm,true);

void hoge(){ FOR(i,2,mm) for(int j = 2; i*j <= mm; j++) d[i*j] = false; }

void solve() {
    vector<int> dp(mm,INF);
    int val;
    int m = 2;
    dp[m] = 1;
    d[0] = d[1] = dp[0] = dp[1] = 0;
    hoge();
    while(cin >> val){
        if(dp[val] == INF){
            FOR(i,m+1,val+1){
                dp[i] = dp[i-1] + (d[i] ? 1 : 0);
            }

            m = val;
        }
        cout << dp[val] << endl;
    }
}

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

    solve();

    return 0;
}

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

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

	while( cin >> n ){		
		ans = 0;
		for(int i=0 ; i<=n ; i++){
			if(p[i]){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

C++: #include<stdio.h>

int	main(){
	int	i,	k,	x,	cnt[1000001],	data[1000000];
	cnt[0]	=	0;
	data[0]	=	0;
	data[1]	=	0;
	for(i	=	2;	i	<=	1000000;	i++){
		data[i]	=	1;
	}
	for(i	=	2;	i	*	i	<=	1000000;	i++){
		if(data[i]){
			for(k	=	2	*	i;	k	<=	1000000;	k	+=	i){
				data[k]	=	0;
			}
		}
	}
	for(i	=	0;	i	<=	1000000;	i++){
		cnt[i	+	1]	=	cnt[i]	+	data[i];
	}
	while(scanf("%d",	&x)	!=	EOF){
		printf("%d\n",	cnt[x	+	1]);
	}
	return	0;
}

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

int judgeprime(long num){
  int primeflag=1,i;

  if(num%2==0){primeflag=0;}
  else for(i=3;i<sqrt(num);i+=2){

    if( num%i==0 ){
      primeflag=0;
      break;
    }

  }

  if(num==0||num==1||num==4){primeflag=0;}
  else if(num==2){primeflag=1;}

  return primeflag;

}

int main(void){
  long i,num;
  int much;

  while( scanf("%ld",&num) != -1 ){

    much=0;

    for(i=1;i<=num;i++){
      much+=judgeprime(i);
    }

    printf("%d\n",much);

  }

  return 0;  
}
04:57:02 ~/programming/AOJ 
$

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

int p_num[1000000] = {} ;
int d[1000000] = {} ;

void cal(){
	for( int i=2 ; i<1000000 ; i++ ){
		if( p_num[i] == 0 ){
			for( int j=2 ; j<1000000 ; j++ ){
				if( i*j > 1000000 ) break ;
				p_num[i*j] = 1 ;
			}
		}
	}
	
	for( int i=2 ; i<1000000 ; i++ ){
		if( p_num[i] == 0 ) d[i] = d[i-1] +1 ;
		else d[i] = d[i-1] ;
	}
}

int main(){
	
	cal() ;
	
	int n ;
	while(1){
		cin >> n ;
		if( cin.eof() ) break ;
		
		cout << d[n] << endl ;
	}
	
return 0 ;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
//素数かどうかが真のものの数（カウントアップ）を返す
int countup(vector<bool>::iterator begin, vector<bool>::iterator end) 
{
    int counter = 0;
    while (begin++ != end) {
        if (*begin) 
            counter++;
    }
    return counter;
}
int main()
{
    int n;
    
    while (cin >> n) {
        int                     max = sqrt(static_cast<double>(n));
        vector<bool>            is_prime(n, true);
        vector<bool>::iterator  begin, end;
 
        is_prime[0] = is_prime[1] = false;
        
        for (int i=2; i<=max; i++) {
            if (!is_prime[i]) {
                continue;
            }
            else { // iがもし素数だったら、(自分以外の)その倍数全部潰す
                for (int cntr = 2, j = 2*i; j<=n; j = i*(cntr++)) { 
                    is_prime[j] = false;
                }
            }
        }
        begin   = is_prime.begin();
        end     = is_prime.end();
        cout << countup(begin, end) << endl;
    }
}

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

int main(){
	const int max_num=1000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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

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

main()
{
    int ans;
    int buff;
    while(cin >> buff)
    {
        ans  = 0;
        for(int d =2; d <= buff; d++)
        {
            if(isprime(d)) ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <vector>
#define MAX 100000
using namespace std;

int main(){
  //bool num[MAX];
  pair<bool,int> num[MAX];
  int count=0;
  int input=0;
  cin >> input;
  for(int i=2; i<MAX; i++){
    num[i].first=true;
    num[i].second=i;
  }
  for(int i=2;i<input+1;i++){
    if(num[i].first){
      //cout << num[i].second <<",";
      count++;
      for(int j=i+i; j<MAX; j+=i){
        num[j].first=false;
      }
    }
  }
  cout << count << endl;
//cout << MAX <<"までの素数の個数:"<< count  << endl;
  return 0;
}