Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

const int N = 100000;

int main(void)
{
    bool a[N];
    int prime[N], n, count = 0;
    rep(i,N)
        a[i] = true;
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
    {
        rep(i,n)
        {
            if(a[i] == true)
                count++;
        }
        cout << count << endl;
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

bool pr(int n) {
    int i=2;
    while (i*i<=n) {
        if (n%i==0) return false;
        i++;
    }
    return true;
}


int main(){
    bool b[1000000]={0};
    for (int i=0;i<1000000;i++) {
        b[i]=pr(i);
    }
    int n;
    b[0]=0,b[1]=0;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for (int i=1;i<=n;i++){
            if (b[i]==true) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int get_numprime( int num );
bool prime( int n );


int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		cout << get_numprime( num ) << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はすでにカウント

	for( int i = 3 ; i <= num ; i+=2 )
	{
		if( prime(i) ) numprime++;
	}

	return numprime;
}

bool prime( int n )
{
	for( int i = 2 ; i <= n/2 ; i++ )
	{
		if( n%i == 0 )
		{
			return false;
		}
	}
	return true;
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n * 1.0); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

C++: #include <iostream>
#include <numeric>

#define MAX 1000000

using namespace std;

int main() {
	bool prime[MAX];
	fill(prime, prime + MAX, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i < MAX; i++) {
		for (int j = 2; i * j < MAX; j++) {
			if (!prime[i * j]) {
				continue;
			}
			prime[i * j] = false;
		}
	}

	int n, count;
	while (cin >> n) {
		count = 0;
		for (int i = 2; i <= n; i++) {
			if (prime[i]) {
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(int argc, char *argv[]){
	int n;
	while(cin>>n){
		bool check[999999]={false};
		int count=0;
		for(int i=2;i<=n;i++){
			if(!check[i]){
				for (int j = 1; i*j <= n;j++){
					check[i*j]=true;
				}
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    int j,s[1000000]=0;
    long i,n,d=0;
    
    for(i=3;i<1000000;i++){
        for(j=2;j*j<i;j+=2){
            if(j%i==0){
                d--;
                break;
            }
            if(j==2)
                j=1;
        }
        s[i] = ++d;
    }
    
    while(EOF != scanf("%d",&n)){
        printf("%d\n",&d);
    }
    
    
    return 0;
}

C++: #pragma GCC optimize(2)
#define LOCAL0
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
#define xx first 
#define yy second
#define INF 0x3f3f3f3f
void read(int &p)
{
    p=0;int flag=1;char c=getchar();
    while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();}
    while(isdigit(c)) {p=p*10+c-'0';c=getchar();}p*=flag;
}
//n以内素数个数
const int maxn=1000000;
int prime[maxn];
bool is_prime[maxn+1];
int sieve(int n){
    int p=0;
    for(int i=0;i<=n;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}
int cnt,a[35],m;
int main()
{
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    while(cin>>a[++cnt]){
        cout<<sieve(a[cnt])<<endl;
    }
    return 0;
}

C++: #include <stdio.h>

int main(void){

	int num;
	int cnt1 = 0, cnt2 = 0;
	int i, j;

	while(scanf("%d", &num) != EOF){
		for(i = 2; i <= num; i++){
			for(j = 2; j <= num; j++){
				if(i % j == 0){
					cnt1++;
				}
			}
			if(cnt1 == 1) cnt2++;
			cnt1 = 0;
		}
		printf("%d\n", cnt2);
		cnt2 = 0;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <cstring>
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int res[1000010];
int N = 1000010;
void isPrime(){
  for (int i=2; i<N; ++i)res[i] = 1;
  res[0] = res[1] = 0;
  for (int i=2; i<1000; ++i) {
    if (res[i * i]) {
      int j = i + i;
      for (;j < N; res[j] = 0, j += i); 
    }
  }
  for (int i=1; i<N; ++i) res[i] += res[i-1];
}
int main(void){
  int n;
  isPrime();
  while(cin>>n,n){
    cout<<res[n]<<endl;
  } 
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while (1)
	{
		int tmp;

		cin >> tmp;

		if (!tmp)
		{
			return 0;
		}

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;
	}

	return 0;
}

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

int main(){
	int n,w=1;
	cin >> n;
	for(int j=n;j>1;j--){
		for(int i=2;i<j;++i){
			if(j%i == 0){
				break;
			}
			if(i==j-1){
				cout << j << endl;
				w++;
			}
		}
	}
	cout << w;	
	return 0;
}