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>
#include <cmath>

using namespace std;

bool isprime_ge3(int n) {
	if (!(n&1))
		return false;
	int lim = (int)sqrt((double)n);
	for (int i = 3; i <= lim; i+=2)
		if (!(n%i))
			return false;
	return true;
}

int main(void) {
	int n;
	while (cin >> n) {
		if (n < 2)
			cout << 0 << endl;
		else if (n == 2)
			cout << 1 << endl;
		else {
			int total = 1;
			for (int i = 3; i <= n; i++) {
				if (isprime_ge3(i))
					total++;
			}
			cout << total << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>
#define REP(i,n) for(int (i) = 0; i <= n; ++i)
#define N 1000000
using namespace std;

vector<int>prime;

void Eratosthenes(){
    bool f[N];
    for(int i = 0; i < N; i++){
        f[i] = true;
    }
    f[0]=f[1]=false;
    
    for(int i = 2; i < sqrt(N); i++){
        if(f[i]){
            for(int j = 0; i * (j + 2) < N; j++){
                f[i *(j + 2)] = false;
            }
        }
    }
    
    for(int i = 2; i < N; i++){
        if(f[i]){
            prime.push_back(i);
        }
    }
}

int main() {
    int n;
    Eratosthenes();
    while(cin>>n){
        int ret = 0;
        for (int j = 0; j < prime.size(); j++) {
            if (prime[j] > n)break;
            ret++;
        }
        cout<<ret<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <ctime>
#define pb(x) push_back(x)
#define me(x,y) memset(x,y,sizeof(x))
#define sd(x) scanf("%d",&x)
#define ss(x) scanf("%s",x)
#define sf(x) scanf("%f",&x)
#define slf(x) scanf("%lf",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define pc(x) printf("%c",x)
#define pn() printf("\n")
#define plld(x) printf("%lld\n",x)
#define ps(x) printf("%s\n",x)
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<y?x:y)
#define sum(x,y) (x+y)
#define INF 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn=999999+5;

bool vis[maxn];
int prime[maxn];
int sum[maxn];

int get_prime() {
    me(vis,true);
    vis[0]=vis[1]=true;
    int cnt=1;
    for(int i=2;i<maxn;i++) {
        if(vis[i]) prime[cnt++]=i;

        for(int j=1;j<cnt && i*prime[j]<maxn;j++) {
            vis[i*prime[j]]=false;
            if(i%prime[j]==0) break;
        }
    }
    return cnt;
}

void solve() {
    int cnt=get_prime();
    me(sum,0);
    prime[0]=0;
    for(int i=1;i<cnt;i++) {
        for(int j=prime[i];j<prime[i+1];j++) sum[j]=i;
    }
}


int main() {
    solve();
    int n;
    while(sd(n)!=EOF) pd(sum[n]);
	return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[] = { 2, 3, 5 }, i, x, y = 3,n,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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

    while(true){
	int n;
	cin >> n;
	if(cin.eof()) break;

	int res = 0;
	bool flg = true;
	for(int i=2;i<=n;i++){
	    flg = true;
	    for(int j=2;j*j<=i;j++){
		if(i % j == 0) flg = false;
	    }
	    if (flg) res++;
	}
	cout << res << endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

void solve(int n) {
	int prime[n];
	int j=0;
	for (int i=2; i<=n; i++) {
		prime[j] = i;
		j++;
	}
	int p;
	for (int i=0; i<n; i++) {
		p = prime[i];
		if (p == -1) continue;
		for (int k=i+1; k<n; k++) {
			if (prime[k]%p == 0)
				prime[k] = -1;
		}
	}
	int count = 0;
	for (int i=0; i<n; i++)
		if (prime[i] != -1) count++;
	cout << count << endl;
}

int main() {
	int n;
	while (cin >> n) {
		if (n<=1) cout << 0 << endl;
		solve(n);
	}
	return 0;
}

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

int main(){
int n;
while(cin>>n){
	int m=0;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
}
return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MAX_N 11111111
using namespace std;
int prime[MAX_N];
bool is_prime[MAX_N];
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] == true){
      prime[p++] = i;
      for(int j=2*i;j<=n;j+=i)is_prime[j] = false;
    }
  }
  return p;
}
int main(){
  int n;
  while(cin >> n){
    cout << sieve( n ) << endl;
  }
}

C++: #include <stdio.h>

int main(){
	long sosuu[200000] = { 2 }, i, x, y = 1, z = 0;


	while(scanf("%d", &z)!=EOF){//入力した数以下の素数を表示

		for (i = 3; i < z + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++; }
			}
		}
		if (z < 2){ y = 0; }
	printf("%d\n", y);//最後に素数の合計数を表示

	for (i = 1; i < y; i++){
		sosuu[i] = 0;
	}y = 1; z = 0;
	}

	return 0;
}

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

int GetPrimeCount(int n)
{
	vector<bool> IsPrimeNumber(n+1, true);
	for(int i = 2; i <= n; i++){
		while(IsPrimeNumber[i] == false){
			i++;
		}
		for(int j = 2; i*j <= n; j++){
			IsPrimeNumber[i*j] = false;
		}
	}
	int Count = 0;
	for(int i = 2; i <= n; i++){
		if(IsPrimeNumber[i] == true){
			Count++;
		}
	}
	return Count;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(cin.eof() == true) break;
		cout << GetPrimeCount(n) << endl;
	}
	return 0;
}

C++: #include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j-1] = true;
		}
		}
	}
	for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
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); 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>
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>
using namespace std;
 
bool IsPrime(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  int prime[1000000]={};
  for(int i=2;i<=1000000;i++){
      if(IsPrime(i)) prime[i]=prime[i-1]+1;
      else prime[i]=prime[i-1];
  }
   
  while(cin >> n) cout << prime[n]<< endl;

   
   return 0;
}