Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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

using namespace std;

int main(){
    int n;
    bool p[1000000];
    while(cin>>n){
        int n_sq = (int)sqrt(n);
        for(int i=0; i<n; i++){
            p[i] = true;
        }
        p[0] = false;

        for(int i=1; i<n_sq; i++){
            if(p[i]){
                for(int j=i*2+1; j<n; j=j+(i+1)){
                    p[j] = false;
                }
            }
        }

        int cnt=0;
        for(int i=0; i<n; i++){
            if(p[i]){
                cnt++;
            }
        }

        cout<<cnt <<endl;

    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
 int main(){
    int n,cnt=0;
    cin >> n;
    vector<bool>m(n+1,true);
    for(int i=2;i*i<=n;i++)
         if(m[i]) for(int j=i+i;j<=n;j+=i)  m[j]=false;        
    for(int i=2;i<=n;i++)
            if(m[i]) { cnt++;}
    cout << cnt << endl;    
    return 0;
}

C++: #include<cstdio>
using namespace std;
bool prime[1000000];
#define max 1000000
int main(){
	prime[1] = true;
	for(int i = 2; i * i < max; i++){
		if(!prime[i]){
			for(int j = i * i; j < max; j+=i){
				prime[j] = true;
			}
		}
	}
	int n;
	while(scanf("%d",&n) != EOF){
		int ans = 0;
		for(int i = 1; i <= n; i++){
			if(!prime[i])ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int prime(int n) {
	int k; int m[] = {2, 3, 5, 7, 11, 13,17, 19, 23, 29, 31, 37, 41};
	if(n == 2) return 1;
	if(n % 2 == 0) return 0;
for(k = 0; k < sizeof(m)/4; k++)
if(n % m[k] == 0) return 0;
	for(k = 3; k * k <= n; k += 2) {
		if(n % k == 0) return 0;
	}
	return 1;
}

int cntPrime(int n) {
	int cnt = 0, i, k;
	for(i = 2; i <= n; i++) {
		cnt += prime(i);
	}
	return cnt;
}

int main() {
	int a;
	int arg[1024] = { 0 };
	int cnt = 0;
	while(scanf("%d", &a) != EOF) {
		arg[cnt++]=a;
	}
	int i;
	for(i = 0; i < cnt; i++) {
printf("%d\n", cntPrime(arg[i]));
	}
}

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

int is_prime(int);

int main()
{
	int input_count;
	int prime_count;
	int input;
	int for_cnt;
	int output[30];
	
	
	input_count = 0;
	
	while(scanf("%d", &input) != EOF && input_count < 30)
	{
		prime_count = 0;
		
		if(input >= 2)
		{
			prime_count++;
		}
		for_cnt = 3;
		while(for_cnt <= input)
		{
			if(is_prime(for_cnt))
			{
				prime_count++;
			}
			for_cnt += 2;
		}
		output[input_count] = prime_count;
		input_count++;
	}
	
	for(for_cnt = 0; for_cnt < input_count; for_cnt++)
	{
		printf("%d\n", output[for_cnt]);
	}
	
    return 0;
}

int is_prime(int test_num)
{
	int divisor;
	
	if(test_num == 1)
	{
		return 0;
	}
	else if(test_num == 2 || test_num == 3 || test_num == 5 || test_num == 7)
	{
		return 1;
	}
	
	else if((test_num % 2) == 0)
	{
		return 0;
	}

	for(divisor = 3 ; divisor <= (sqrt(test_num) + 1); divisor += 2)
	{
		if(test_num % divisor == 0)
		{
			return 0;
		}
	}
	
	return 1;
}

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

#define NUM_MAX		1000001

int prime(int num_max)
{
	static int numary[NUM_MAX];
	static int primeary[NUM_MAX];
	static int primeary_len = 1;
	static int num = 2;
	primeary[0] = 2;
	numary[0] = 0;
	numary[1] = 0;
	numary[2] = 1;
	if(num_max > num)
	{
		for(num++;num <= num_max;num++)
		{
			int i;
			for(i = 0;i < primeary_len;i++)
			{
				if(!(num % primeary[i]))
				{
					numary[num] = numary[num-1];
					break;
				}
				else if(num < (primeary[i] * primeary[i]))
				{
					numary[num] = numary[num-1] + 1;
					primeary[primeary_len] = num;
					primeary_len++;
					break;
				}
			}
		}
	}
	return numary[num_max];
}

int main()
{
	int n;
	while(scanf("%d",&n) != EOF)
	{
		printf("%d\n",prime(n));
	}
}

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

using namespace std;

int main(){
}

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;

int power(int b,int e,int p){
	int ret = 1;
	while(e>0){
		if((e&1)!=0){
			ret = (ret*b)%p;
		}
		b = (b*b)%p;
		e>>=1;
	}
 	return ret%p;
}

bool fermat(int p){
	if(p!=2 && p%2==0)return false;
	if(p!=3 && p%3==0)return false;
	if(p!=5 && p%5==0)return false;
	if(p!=7 && p%7==0)return false;
	if(p!=11 && p%11==0)return false;
	if(p!=13 && p%13==0)return false;
	for(int x=0;x<100;++x){
		int a = rand()%(p-1)+1;
		if(power(a,p-1,p)!=1)return false;
	}
	return true;
}
int main(){
	int n;
	while(scanf("%d",&n)==1){
		int tot = 0;
		if(n>=2)++tot;
		for(int x=3;x<=n;x+=2){
			if(fermat(x))++tot;
		}
		cout<<tot<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	cin >> n;
	
	for(int a = 3;a<=n;a++)
	{
		prime[a] = 1;
		for(int b = 2;b<a;b++)
		{
			if(a%b==0)
			{
				prime[a] = 0;
				break;
			}
		}
		primesum[a] = primesum[a-1]+prime[a];
	}
	while(cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define MAX_N 100000

using namespace std;
void q9() {
	bool IsPrime[MAX_N];
	memset(IsPrime, 1, sizeof(IsPrime));
	IsPrime[0] = false;
	IsPrime[1] = false;
	for (int i = 0; i < sqrt(MAX_N); i++) {
		if (!IsPrime[i]) continue;
		for (int j = i * 2; j < MAX_N; j += i) {
			IsPrime[j] = false;
		}
	}

	int NofP[MAX_N];
	NofP[0] = 0;
	for (int i = 1; i < MAX_N; i++) {
		NofP[i] = NofP[i - 1] + IsPrime[i];
	}

	int n;
	for (; cin >> n;) {
		cout << NofP[n] << endl;
	}
}

int main() {
	q9();
	return 0;
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int count=0;
		for(int i=2;i<=n;i++){
			int j=2;
			while(true){
				if(i%j==0)
					break;
				if(j>(int)sqrt((double)i)){
					count++;
					break;
				}
				j++;
			}
		}
		cout<<count+1<<endl;
	}
	return 0;
}

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

const int maxn = 1e6 + 15;
bool is_prime[maxn];
int sieve(int x){
	int res = 0;
	fill(is_prime+2,is_prime+x+1,true);
	for(int i = 2; i <= x; i++) if(is_prime[i]){
		res++;
		for(int j = 2 * i; j <= x; j += i) is_prime[j] = false;
	}
	return res;
}

int main(){
	int n;
	while(scanf("%d", &n) == 1) printf("%d\n", sieve(n));
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,count=0;
  while(scanf("%d",&n)!=EOF){
    int data[n+1];
    for(int i=2;i<=n;i++){
      data[i]=0;
    }
    for(int i=2;i<=n;i++){
      if(data[i]!=-1){
	count++;
	for(int j=i;j<=n;j+=i){
	  if(data[j]!=-1){
	  data[j]=-1;
	  }
	}
      }
    }
    cout << count << endl;
    count=0;
  }
  return(0);
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n,a,b;
    char x[1000000];
    while(~scanf("%d",&n)){
        memset(x,0,sizeof(x));
        for(a=2;a<=n/2;a++)for(b=a*2;b<=n;b+=a)x[b]=1;
        for(a=2,b=0;a<=n;a++)if(!x[a])b++;
        printf("%d\n",b);
    }
    return 0;
}