Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		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:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[999999]={0,0,1,2},n,k=0,count=2;
	for(int i=4;i<999999;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){k++;break;}
		}
		if(k==1)count++;
		a[i]=count;
		k=0;
	}
	while(cin>>n)cout<<a[n]<<endl;
	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;
                    break;
            }
	    }
	    if (flg) res++;
	}
	cout << res << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#define MAX 1000010

int is_prime[MAX];

void sieve(){
  int i,j;
  for(i=0;i<=MAX;i++)is_prime[i]=1;
  is_prime[0]=is_prime[1]=0;
  for(i=2;i<=MAX;i++){
    if(is_prime[i]){
      for(j=2*i;j<=MAX;j+=i)is_prime[j]=0;
    }
  }
}

int main(){
  int a,i;
  int sum[MAX];
  sieve();
  for(i=0;i<MAX;i++)sum[i]=0;
  for(i=1;i<MAX;i++)sum[i]=sum[i-1]+is_prime[i];
  while(scanf("%d",&a)!=EOF){
    printf("%d\n",sum[a]);
  }
  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define NUM 1000000
int main(){
	long int n;
	int p[NUM],i,j,k,a,b;
	for(i=0;i<NUM;i++){
		p[i]=0;
	}
	for(i=2;i<NUM;i++){
		if(p[i]==0){
			p[i]=2;
			for(j=2;j<=(NUM/i);j++){
				p[i*j]=1;
			}
		}	
	}
	while(cin>>n){
		a=0;
		for(i=2;i<=n;i++){
			if(p[i]==2)a++;
		}
		cout<<a<<endl;
	}

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
#define ll long long
typedef pair<int, int> P;

bool prime[1000005];

void solve()
{
	REP(i, 1000005)prime[i] = true;
	prime[0] = prime[1] = false;
	for (int i = 2; i*i <= 1000000;i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; j*i <= 1000000; j++){
				if (prime[i*j] == true)prime[i*j] = false;
			}
		}
	}
}

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

		int ans = 0;

		solve();
		REP(i, n + 1){
			if (prime[i] == true){
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    bool isPrime[n_size];
    isPrime[0]=false; isPrime[1]=false;

    for(unsigned i=2;i<n_size;i++)
        isPrime[i] = true;

    for(unsigned i=2;i*i<n_size;i++){
        if(isPrime[i]){
            for(unsigned j=(i*i);j<n_size;j+=i)
                isPrime[j] = false;
        }
    }

    unsigned n_prime[n_size];

    unsigned cnt = 0;
    for(unsigned i=0;i<n_size;i++){
        if(isPrime[i])
            cnt++;
        n_prime[i] = cnt;
    }

    unsigned n;
    while(cin>>n){
        cout << n_prime[n] << endl;
    }

    return 0;
}

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

int main() {
	int n;

	while (std::cin >> n) {
		std::vector<int> nums;
		++n;
		for (int i = 0; i < n; ++i) {
			nums.push_back(i);
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) < 2) continue;
			for (int j = nums.at(i) * 2; j < n; j += nums.at(i)) {
				nums.at(j) = 0;
			}
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) > 1) {
				++c
			}
		}
	}
	return 0;
}

C++: //36
#include<iostream>

using namespace std;

int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
	cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

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

bool isPrime(int x){
	if(x == 0 || x == 1) return false;
	for(int i=2;i<x;i++){
		if(x % i == 0) return false;
	}
	return true;
}

int main(void){
	int n;
	int ans = 0;
	
	cin>>n;
	for(int i=2;i<=n;i++){
		if(isPrime(i)) ans++;
	}
	printf("%d\n",ans);

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	long int n,f,k,i;
	int count;
	bool chk;
	scanf("%d",&n)!=EOF);
		count=0;
		for(i=2;i<=n;i++){
		
			chk=0;
			f=i/2;
			k=2;
		
			while(f>=k){
				if((i%k)==0){
					chk=true;
					break;
				}
				k++;
			}
		
			if(chk==false){
				count++;
			}
		}
		cout<<count<<endl;
	
}

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

int main(int argc, const char * argv[])
{
    long int n;
    while (cin >> n) {
        int pnm = 0;
        for (long int i = 2; i <= n; i++) {
            int cnt = 0;
            for (long int j = 2; j <= i; j++) {
                if (i % j == 0) {
                    cnt++;
                }
            }
            if (cnt == 1) {
                pnm++;
            }
        }
        cout << pnm << endl;
    }
    
    return 0;
}

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

int eratos(int n){
	vector<int> v;
	for(int i=0; i<=n; i++) v.push_back(i);
	v[1]=0;
	for(int i=2; i<=(int)sqrt((double)n); i++){
		if(v[i]!=0){
			for(int j=2; i*j<=n; j++){
			v[i*j]=0;
			}
		}
	}
	int count=0;
	for(int i=2; i<=n; i++)
		if(v[i]!=0) count++;
	return count;
	return 0;
}

int main(void){
	int n;
	while(cin >> n)
		cout << eratos(n) << endl;
	return 0;
}

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


using namespace std;



bool isPrime(int num) {
	if (num < 2)return false;
	if (num == 2)return true;
	if (num % 2 == 0)return false;
	int root = (int)sqrt(num);
	for (int i = 3; i <= root; i += 2) {
		if (num % i == 0)return false;
	}
	return true;
}

int main() {

	int num;
	while (cin >> num) {
		int count = 0;
		if (num >= 2)count++;

		for (int i = 3; i <= num; i += 2) {
			if (isPrime(i))count++;
		}
		cout << count << endl;
	}


	
	//std::system("pause");
	return 0;
}

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

using namespace std;

const int MAX_N = 1000000;

int N;

int len;
int prime[MAX_N];				//save all prime number less than MAX_N
bool isPrime[MAX_N];

void sieve(){
	//init
	fill(isPrime, isPrime + MAX_N, true);
	isPrime[0] = isPrime[1] = false;
	
	for(int i = 2; i < MAX_N; i ++){
		if(isPrime[i]){
			prime[len ++] = i;
			for(int j = 2 * i; j < MAX_N; j += i)
				isPrime[j] = false;
		}
	}
}

void solve(){
	int ans = 0;
	for(int i = 0; i < len; i ++){
		if(N >= prime[i])
			ans ++;
	}
	printf("%d\n", ans);
}

int main(int argc, char const *argv[]){

	sieve();
	while(scanf("%d", &N) != EOF){
		solve();
	}

	return 0;
}

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