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 <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; continue;}
    for(int i=2; i<=n; i++) prime[i]=true;
    int ans=0;
    for(int i=2; i<=n; i++){
      if(prime[i]) {
        ans++;
        for(int j=2*i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}

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

int main(){
        int n;
        int d; //素数を入れるための添字
        bool count; //割りきれるかどうかの判定
        int number[400000]; //素数を入れておく
        number[0] = 2;
        
        
        while(cin >> n != 0){
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++)
                                if(i % number[j] == 0)
                                        count = false;
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                }
        cout << d+1 << endl;
        }
}

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

int main(){
	using namespace std;
	while(1){
		int n,i,j=2,count = 0;
		cin >> n;
		if (cin.eof() || n == 0) break;
		int prime[n+1];
		for(i=2;i<=n;i++) prime[i] = 1;
		for(i=2;i<=n;i++){
			if(prime[i] == 0) continue;
			else{
				for(j=2*i;j<=n;j++){
					if(j%i == 0) prime[j] = 0;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(prime[i] == 1) count += 1;
		}
		cout << count << endl;
	}
	return 0;
}

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

class prime{
	int sum;
	char p[MAX];
public:
	prime();
	int num(int n);
};

prime::prime(){
	p[0]=0;
	p[1]=0;
	p[2]=1;
	for(int i=3;i<MAX;i+=2)p[i]=1;
	for(int i=4;i<MAX;i+=2)p[i]=0;
	
	int c=3;
	while(c<1000){
		for(int i=c+2;i<MAX;i+=2){
			if(i%c==0)p[i]=0;
		}
		while(p[++c]==0);
	}
}

int prime::num(int n){
	sum=0;
	for(int i=0;i<=n;i++)sum+=p[i];
	return sum;
}

int main()
{
	int n;
	prime pr;
	while(cin >> n){
		cout << pr.num(n) << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int n;
bool is_prime[1000000];

int solve()
{
    int result = 0;
    for (int i = 0; i <= n; ++i)
    {
        is_prime[i] = true;
    }

    for (int i = 2; i <= n; ++i)
    {
        if (!is_prime[i])
        {
            continue;
        }
        ++result;
        for (int j = i * 2; j <= n; j += i)
        {
            is_prime[j] = false;
        }
    }
    return result;
}

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

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

int main()
{
	int i;

	for (i=0; i<999999; i++)
	{
		int num, j=2, count = 0;				
		scanf("%d", &num);

		int* check = (int*) malloc(sizeof(int)*num);			

		int k;
		for (k=0; k<num; k++)
		{
			check[num] = 0;
		}

		if (num == 2)
		{
			count++;
		}
		for (j=j; j<num; j++) 
		{
			if (check[j] == 1)
				continue;
			
			count++;

			int l;		
			for (l=2; l * j < num; l++)
			{				
				check[j * l] = 1;
			}			
		}
		printf("%d\n", count);
		free(check);
	}

	return 0;
}

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

    return 0;
}

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

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
int res=0;
scanf("%d",&n);
for(int i=2;i<=n;i++){
if(is_prime(n)) res++;
}
printf("%d\n",res);
}

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

int main(){
	int i,j,n;
	bool prime[1000001];
	for (i = 3; i <= 1000000; i += 2){
		prime[i] = true;
	}
	prime[2] = true;

	for (i = 3; i <= 1000; i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 1000000 / i; j += 2){
				prime[i * j] = false;
			}
		}
	}
	while(cin >> n && n){
		int count = 0;
		for(i=2;i<=n;i++){
			if(prime[i] == true) count++;
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int a,f,counter;
    while(cin>>a)
    {
        counter=1;
        for(int i=3;i<=a;i++)
        {
            f=0;
            for(int j=2;j<i;j++)
            {
                if(i%j==0)
                    f=1;
            }
            if(f==0)
                counter++;
        }
        cout<<counter<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,i,j;
    while(cin>>a){
        b=0;
        for(i=2;i<=a;i++){
            c=0;
            for(j=2;j*j<=i;j++){
                if(i%j==0){c++;break;}
            }
            if(i==2||i==3)c++;
            if(c==0)b++;
            if(i==2||i==3)b++;
        }
        cout<<b<<endl;
    }
    return 0;
}

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

using namespace std;

#define MAX 10000000
#define LMT 3163
int sieve();
int calculation();

unsigned flag[MAX>>6];
int primes[5761455];

#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))

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


int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    calculation();
    return 0;
}

int calculation()
{
    int Rang, count;
    unsigned int i;
    int k = 1;
    primes[0] = 2;
    for( i=3; i<MAX; i+=2)
    {
        if(ifc(i)==0)
            primes[k++] = i;
    }
    while(scanf("%d",&Rang)==1)
    {
        count = 0;
        for(i=0; i<Rang; i++)
        {
            if(primes[i]<=Rang)
            {
                count++;
            }
            else if(primes[i]>Rang)
                break;
        }
        cout << count << "\n";
    }
    return 0;
}