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 || num == 5:
		return true
	case num < 2 || num%2 == 0 || num%5 == 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<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;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int N=1000000;
vector<bool> pr(N,true);
vector<int> p;

void init()
{
	int i,j;
	p.reserve(80000);
	p.push_back(2);
	for(i=3;i*i<N;i+=2)
		if(pr[i]) {
			p.push_back(i);
			for(j=i;i*j<N;j+=2) pr[i*j]=false;
		}
	for(;i<N;i+=2) if(pr[i]) p.push_back(i);
}

int main()
{
	int n;
	init();
	while(cin>>n) {
		cout<<upper_bound(p.begin(),p.end(),n)-p.begin()<<endl;		
	}
	return 0;
}

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

struct theSieveOfEratosThenes {
	vector<bool> prm;

	theSieveOfEratosThenes(int n) {
		prm = vector<bool>(n + 1, true);
		prm[0] = prm[1] = false;
		for (int i = 2; i * i <= n; ++i) {
			if (prm[i]) {
				for (int j = 2 * i; j <= n; j += i) prm[j] = false;
			}
		}
	}

	bool isPrimeNumber(int a) {
		return prm[a];
	}
};

int main() {
	int n;
	theSieveOfEratosThenes tsoet(999999);
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (tsoet.isPrimeNumber(i)) ++ans;
		}
		cout << ans << endl;
	}
}

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

		getline(cin, &tmpstr);

		tmp = atoi(tmpstr.c_str());

		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;

		//if (cin.eof()) { break; }
	}

	return 0;
}