Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

#define MAX 999999

using namespace std;

int num_prime[MAX+1];
bool not_prime_flag[MAX+1];

int main()
{
    int n;

    for (int i = 2; i < MAX+1; ++i) {
        if(!not_prime_flag[i]){
            for (int j = 2; i*j < MAX+1; ++j) {
                not_prime_flag[i*j] = true;
            }
        }
        num_prime[i]=num_prime[i-1]+!not_prime_flag[i];
    }
    while (cin>>n){
        cout<<num_prime[n]<<endl;
    }
    return 0;
}

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

using namespace std;
int c = 0;
int i = 1;
unsigned long long a = 0;
unsigned long long b = 0;
unsigned long long sosuu[1000000] = { 0 };
int pattara = 0;

int sub(int c) {

	
	
	
	for (int i = 2; i<=c; i++){
		
		for (int q = 1; q <= sqrt(i); q++) {
			sosuu[pattara] = i;
			if (sosuu[pattara] % 2 == 0 && sosuu[pattara]!= 2) {
				break;
			}
			if (sosuu[pattara] % q == 0) {
				b += 1;
			}

		}

		if (b == 1) {
			
			pattara++;
			
		}
		b = 0;
		
	}

	
	return 0;
}


int main(){
	while (scanf("%d", &c) != EOF){

		sub(c);
		cout << pattara << endl;
		pattara = 0;
		
	}

	return 0;
}

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

using namespace std;

int A[1000000];
int Eratosthenes(int n)
{
	int mama = 0;
	for (int i = 0; i < n; i++)
	{
		A[i] = 1;
	}
	for (int i = 2; i < sqrt(n); i++)
	{
		if (A[i])
		{
			for (int j = 0; i*(j + 2) < n; j++)
			{
				A[i*(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < n; i++)
	{
		if (A[i])
		{
			mama++;
		}
	}
	return mama;
}

int main()
{
	int n;
	cin >> n;
	while (n != -1)
	{
		cout << Eratosthenes(n) << endl;
		cin >> n;
	}
	return 0;
}

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

int main(){
  bool prime[1000000];
  prime[0]=false;prime[1]=false;
  for(int i=2;i<=999999;i++){
    prime[i]=true;
  }

  for(int i=2;i<=sqrt(999999);i++){
    if(prime[i]){
      for(int j=2;j*i<=999999;j++){
        prime[j*i]=false;
      }
    }
  }
  int n;
  while(cin>>n){
    int cnt=0;
    for(int i=2;i<=n;i++){
      if(prime[i])cnt++;
    }
    cout<<cnt<<endl;
  }
}

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

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)

const int limit = 1000000;
std::vector<int> q;

int main(){
    q.push_back(2);
    for(int i = 3; i < limit; i += 2){
        bool f = true;
        FOREACH(it, q){
            int p = *it;
            if(i < p*p) break;
            if(i % p == 0){ f = false; break; }
        }
        if(f) q.push_back(i);
    }
    int n;
    while(std::cin >> n){
        int l = 0, r = q.size()-1, c = -1;
        while(l <= r){
            c = (l + r)/2;
            if(q[c] < n){ l = c + 1; continue; }
            if(q[c] > n){ r = c - 1; continue; }
            break;
        }
        if(l > r) c = r;
        std::cout << c + 1 << std::endl;
    }
}

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

int main(){
	char data[999999];
	
	int i,j,num,check,count = 0;
	
	data[0] = 0;
	data[1] = 1;
	
	for(i=3;i<1000000;i++){
		check = 1;
		if(i%2==0){
			data[i-1]=0;
		}
		if(i%2==1){
			for(j=3;j*j<=i;j+=2){
				if(i%j==0){
					check = 0;
					break;
				}
			}
			if(check == 1){
				data[i-1] = 1;
			}
			else{
				data[i-1] = 0;
			}
		}
	}
	/*
	for(i=0;i<20;i++){
		if(data[i] == 1){
			printf("%d\n",i+1);
		}
	}
	*/
	
	
	while(cin>>num){
		count = 0;
		for(i=0;i<num;i++){
			if(data[i] == 1){
				count++;
			}
		}
		printf("%d\n",count);
	}
	
	
	
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define SIZE 1000000
int main(){
	vector<bool>bo(SIZE,false);
	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			for(int j=i*2;j<SIZE;j+=i){
				bo[j]=true;
			}
		}
	}
	vector<int>ans(SIZE);

	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			ans[i]=ans[i-1]+1;
		}
		else {
			ans[i]=ans[i-1];
		}
	}
	int n;
	while(cin>>n){
		cout<<ans[n]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
#define MAX 1000000
#define LMT 1000
int sieve();
int calculation();
unsigned flag[MAX>>6];

int primes[5761455];
#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))
int main()
{
    sieve();
    return 0;
}

int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    calculation();
    return 0;
}

int calculation()
{
    unsigned int i;
    int k = 1;
    primes[0] = 2;
    for( i=3; i<MAX; i+=2)
    {
        if(ifc(i)==0)
            primes[k++] = i;
    }
    int input;
    int count;
    while(scanf("%d",&input)==1)
    {
        count=0;
        for(i=0; primes[i]<=input; i++)
            count++;
        printf("%d\n",count);
    }
    return 0;
}

C++: #include<stdio.h>



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

	while((scanf("%d",&n)!=EOF)&&(n!=0)){

		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;
}

C++: #include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int n;
	while (std::cin >> n)
	{
		std::vector<bool> v(n + 1 ,false);
		int c = 0;
		v[0] = true, v[1] = true;
		for (int i = 2; i * i <= n ; ++i) {
			if (!v[i]) {
				for (int j = i * i; j <= n; j += i) {
					v[j] = true;
					++c;
				}
			}
		}

		std::cout << n-c-1 << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e8);
bool p[MAX];
short num[MAX];
void isPrime(){
  rep(i,MAX)p[i] = true;
  p[0] = p[1] = false;
  num[0] = num[1] = 0;
  loop(i,2,MAX){
    num[i] = num[i-1] + p[i];
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i){
	p[j] = false;
      }
    }
  }
}

int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<num[n]<<endl;
  
  return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

C++: 
#include <bits/stdc++.h>
using namespace std;

void Sieve(int n)
{
	bool prime[n+1];
	int c=0;
	memset(prime, true, sizeof(prime));

	for (int p=2; p<=n; p++)
	{
		if (prime[p] == true)
		{
			for (int i=p*2; i<=n; i += p)
				prime[i] = false;
		}
	}
	for (int p=2; p<=n; p++)
	if (prime[p])
		c++;
		cout<<c<<endl;
}

int main()
{
	int n;
	while(cin>>n){
        Sieve(n);
	}

	return 0;
}