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 <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// Eratosthenesの篩
vector<bool> primeno(1000010, true);
void Eratosthenes(int n) {
    primeno.at(0) = primeno.at(1) = false;
    int limit = sqrt(n);
    for(int i = 2; i < limit; ++i) {
        if(primeno.at(i)) {
            for(int j = 0; i*(j+2) < n; ++j) {
                primeno.at(i*(j+2)) = false;
            }
        }
    }
}

vector<int> primecnt(1000010, 0);

int main() {
    Eratosthenes(1000000);
    ll n;
    for(int i = 0; i < 1000000; ++i) {
        if(primeno.at(i)) primecnt.at(i)++;
        primecnt.at(i+1) += primecnt.at(i);
    }
    while(cin >> n) {
        cout << primecnt.at(n) << endl;
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
while(cin >> n,!cin.eof()){
vector<int> prime;
prime.push_back(2);//ôðÈ­½ß2ÍÅÉüêÄ¨­
bool flag;
for(int x=3;x<=n;x+=2){
flag=true;
for(int y=0;prime[y]*prime[y]<=x;y++){
if(!(x%prime[y])){
flag=!flag;
break;
}
}
if(flag)prime.push_back(x);
}
cout << prime.size() << endl;
}
return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i<= MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int tmp;
	while (cin >> tmp)
	{
		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++: 

#define MAX 100

main(){
  int in_num;
  int i, put, j, k = 0, l;
  int count = 0;
  int res;
  int pres[MAX], flag = 0;

  while(1){
  res = scanf("%d", &in_num);

  if(res == EOF) break;

  for(i = 1 ; i <= in_num ; i++){
    /* iが現在まで判明している素数の倍数でないかを調べる */
    for(l = 0 ; pres[l] != NULL ; l++){
      if(i % pres[l] != 0){
        flag = 1;
      }
    }
    /* そうでなかったら以下を実行 */
    if(flag == 1){
      for(j = 2 ; j <= i ; j++){
        put = i % j;

        if(put == 0 && i != j) break;

        if(put == 0){
	  if(k < MAX){
	    /* kが最高格納数以下なら素数を保存 */
	    pres[k] = i;
	    k++;
	  }
	  printf("%d\n", i);
          count++;
          break;
        }
      }
    }
  }

  printf("%d\n", count);
  count = 0;
  }
  return 0;
}

C++: #include<stdio.h>
#include<math.h>
#define MAX_S 999999

int main(void) {
	int prime_f[MAX_S], prime_sum[MAX_S], sum = 0, n;

	for (size_t i = 0; i < MAX_S; i++)
	{
		prime_f[i] = 1;
		prime_sum[i] = 0;
	}
	prime_f[0] = 0;

	for (size_t i = 1; i < sqrt(MAX_S); i++)
	{
		if (prime_f[i] == 1) {
			for (size_t j = i + 1; j*(i + 1) <= MAX_S; j++)
			{
				prime_f[(i + 1)*j - 1] = 0;
			}
		}
	}

	for (size_t i = 0; i < MAX_S; i++)
	{
		if (prime_f[i] == 1) sum++;
		prime_sum[i + 1] = sum;
	}

	while (scanf("%d", &n) != EOF)
	{
		printf("%d\n", prime_sum[n]);
	}
	return 0;
}

C++: #include "iostream"
#include "string.h"
using namespace std;
bool visit[1000000];
int prime[1000000];

void isPrime()
{
    int j=0;
    for(int i=2;i<1000000;i++)
    {
        if(visit[i])
            prime[j++]=i;
        for(int t=0;t<j&&i*prime[t]<1000000;t++)
        {
            visit[i*prime[t]]=false;
            if(i%prime[t]==0)
                break;
        }
    }
}

int main()
{
    int N=30;
    int n;
    memset(visit,true,1000000);
    visit[0]=visit[1]=false;
    isPrime();
    while(cin>>n)
    {
        int cnt=0;
        for(int i=2;i<=n;i++)
            if(visit[i])
            cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	int n, p, k, count;
	vector<int> num(1000000, 1);
	while(cin>>n){
		count=0;
		num[0]=0; num[1]=0;
		for(int i=4; i<=n; i+=2){
		num[i]=0;
		}
		for(int i=0; i<=n; i++){
			p = i+i+3;
			for(k=p+p; k<=n; k+=p){
				num[k]=0;
			}
		}
		for(int i=0; i<=n; i++){
			if(num[i]==1)
				count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

bool isPrimes[1000000];

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int res = 0;
		for (int i = 0; i <= n; ++i)
			isPrimes[i] = true;
		isPrimes[0] = isPrimes[1] = false;
		for (int i = 2; i <= n; ++i)
		{
			if (isPrimes[i])
			{
				for (int j = i*2; j <= n; j += i)
					isPrimes[j] = false;
				++res;
			}
		}
		printf("%d\n", res);
	}

	return 0;
}

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

#define N 1000000L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = (int) sqrt(N);
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    std::cout << count << std::endl;
    if(c == EOF) break;
  }
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    while (cin >> n) {
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }
        
        vector<bool> is_prime(n + 1, true);
        is_prime[0] = false; is_prime[1] = false;
        for (int i = 2; i <= n; i++) {
            if (is_prime[i]) {
                for (int j = 2 * i; j <= n; j += i) {
                    is_prime[j] = false;
                }
            }
        }
        
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}