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 <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{

long long  n,f=1,c=0;
cin>>n;
for(long long i=2;i<=n;i++)
{
    if(i==2){f=1;c++;continue;}
    for(long long j=2;j<i;j++)
    {
        if(i%j==0){f=0;break;}
        else f=1;
    }
    if(f==1)c++;
}
cout<<c;
    return 0;
}

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

int a[1000000];

int main()
{
  int n;
  int count;

  for (int i = 2; i < 1000000; i++){
     a[i] = 1;
   }

   for (int i = 0; i * i < 1000000; i++){
     if  (a[i] == 1){
       for (int j = 2; j * i <= 100000; j++){
         a[j * i] = 0;
       }
     }
   }

   while (cin >> n){
     count = 0;
     for (int i = 0; i < 1000000; i++){
       if (a[i] == 1){
         count++;
       }
     }
   }

   cout << n << endl;

   return (1);
}

C++: 
#include<iostream>
#pragma warning(disable:4996)
#define MAX_N 1000000
using namespace std;

int prime[MAX_N];//第i个素数
bool is_prime[MAX_N + 1];//is_pime[i]?true表示i?素数

//返回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]){
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
	}
	return p;

}

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

}

C++: #include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
int prime[maxn];
bool is_prime[maxn];
int sieve(int n) {
	int p = 0;

	for(int i=2; i<=n; i++) {
		if(is_prime[i]) {
			prime[p++] = i;
			for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
		}
	}
	return p;
}
int main() {
	int n;
	for(int i=0; i<=maxn; i++) is_prime[i] = true;
	//0???1???????´???°
	is_prime[0] = is_prime[1] = false;
	while(~scanf("%d",&n)) {

		int p = sieve(n);
		printf("%d\n",p);
	}
}

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 <iostream>
#include <cmath>
#include <cstring>
using namespace std;
const int SIZE = 1000000;
bool mark[SIZE];
long long int num[SIZE];
void findp(){
    memset(mark, true, sizeof(mark));
    for(int i = 2; i <= sqrt(SIZE); i ++){
        if(mark[i]){
            for(int j = i + i; j < SIZE; j += i){
                mark[j] = false;
            }
        }
    }
    num[1] = 0;
    for(int i = 2; i < SIZE; i ++){
        num[i] = num[i-1];
        if(mark[i]){
            num[i] += 1;
        }
    }
}
int main(){
    int n;
    findp();
    while(cin>>n){
        printf("%ld\n", num[n]);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
bool isprime[1000005];
int prime[1000005];
void sieve() {
	for (int i = 0; i <= 1000000; i++) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= 1000000; i++) {
		if (isprime[i]) {
			prime[i] = prime[i - 1] + 1;
			for (int j = 2 * i; j <= 1000000; j += i) isprime[j] = false;
		}
		else prime[i] = prime[i - 1];
	}
}
int main() {
	sieve();
	int n;
	while (cin >> n) {
		cout << prime[n] << endl;
	}
}

C++: #include <stdio.h>
#include <iostream>
 
using namespace std;
 
void uru(int c, int d) {
    int counter = 0;
 
    for (int i = c; i <= d; i++) {
        if (i % 4 == 0) {
            if (i % 100 == 0) {
                if (i % 400 == 0) {
                    cout << i << endl;
                    counter++;
                } 
            } else {
                cout << i << endl;
                counter++;
            }
        }
    }
    if (counter == 0) {
        cout << "NA" << endl;
    }
    //cout << endl;
    return;
}
 
int main() {
    int a,b;
 	bool flag=false;
    while (cin >> a >> b) {
    	if (a == 0 && b == 0) {
            break;
        }
    	if(flag) cout<<endl;
            uru(a,b);
    	flag=true;
    }
	//cout<<000000<<endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N_MAX 1000

using namespace std;

int main(){
	
	int array[N_MAX],i,j,n, num = 0;
	
	while(cin>>n){
		num = 0;
		for (i=0;i<n;i++)
			array[i]=i+2;
		for (i=0;i<n;i++){
			for (j = (i+2); (i+2) * j <= n; j++)
				array[(i+2) * j - 2] = -1;}

	for (i = 0; i < n-1; i++){
    if (array[i] != -1)
	num++;
	}
	cout<<num<<endl;
	}
	cin>>n;
  
	return (0);
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1000000

static bool gosei[MAX];

void b(){
	for(int i=2;gosei[i]==false&&i<MAX;i++)
		for(int j=2,k;(k=i*j)<MAX;j++)
			gosei[k]=true;
}

int c(int n){
	int cnt=0;
	for(int i=2;i<=n;i++)
		if(!(gosei[i]))cnt++;
	return cnt;
}

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

C++: #include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 _Bool *list;
 int n,i,j,cnt;
 
 while(scanf("%d",&n) != EOF)
 {
  cnt = 0;
  list = (int*)calloc(n+1,sizeof(int));
  for(i = 2; i <= n; i++)
  {
   if(list[i] != 1) /*prime number:0 no prime numbers:1*/
   { 
    cnt++;
    for(j = i+i; j <= n; j+=i) list[j] = 1;
   }
  }
  printf("%d\n",cnt);
  free(list);
 } 
 return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#define LIMIT 1000000

int main(){
	int num;
	while( scanf("%d",&num)!=EOF ){
		bool sosu[LIMIT]={0};
		int now=2,count=0;
		while(now<=num){
			if(!sosu[now]){
				count++;
				for(int i=now;i<LIMIT;i+=now){
					sosu[i] = true;
				}
			}
			now++;
		}
		std::cout << count << std::endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define MAX (100000)

int main(void)
{
	int prime[MAX + 1] = {1};
	int n;
	int ans;
	int i;
	char str[100];
	
	for (int i = 0; i <= MAX; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	i = 0;
	while (i * i <= MAX){
		while (prime[++i] != 1 && i * i <= MAX);
		//printf("%d ", i);
		for (int j = 2; j * i <= MAX; j++){
			//printf("%d\n", i * j);
			prime[i * j] = 0;
		}
	}
	
	while (fgets(str, 100, stdin)){
		sscanf(str, "%d", &n);
		
		ans = 0;
		for (int i = 2; i <= n; i++){
			if (prime[i] == 1){
				ans++;
			}
		}
	
		printf("%d\n", ans);
	}
	
	return (0);
}