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>
using namespace std;

#define MAX 1000000
int prime[MAX];

int main()
{
	int number,count=0;
	prime[0] = prime[1] = 0;

	for(int i=2;i<MAX;i++)
	{
		prime[i] = 1;
	}
	for(int i=2;i<1001;i++)
	{
		if(prime[i])
		{
			for(int j=2*i;j<MAX;j += i)
			{
				prime[j] = 0;
			}
		}
	}

	while(cin >> number)
	{
		count = 0;
		for(int i=2;i<=number;i++)
		{
			count += prime[i];
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        bool prime[1000000]={false};
        prime[1]=true;
        prime[2]=false;
        int cou=0;
        for(int i=2;i*i<=n;i++){
            if(!prime[i]){
                for(int j=2;i*j<=n;j++){
                    prime[i*j]=true;
                }
            }
        }
        for(int i=1;i<=n;i++){
            if(!prime[i])cou++;
        }
        cout<<cou<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;


vector<int> p;
int main(void){
    p.pb(2);
    for(int i = 3; i <1000000; i += 2){
        int j;
        for(j = 0; p[j] * p[j] <= i; ++j){
            if(i % p[j] == 0) break;
        }
        if(i % p[j] > 0) p.pb(i);
    }
    int n;
    while(cin >> n){
        int l = 0, r = p.size();
        while(l + 1 != r){
            int t = (l + r)/2;
            if(p[t] <= n) l = t;
            else r = t;
        }
        int ret;
        if(n < p[r]) ret = r;
        else ret = l;
        cout << ret << endl;
    }
    return 0;
}

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

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

using namespace std;

bool is_prime[1000000];
int prime[1000000];

void init_prime()
{
	int n = sizeof(prime)/sizeof(prime[0]);
	int i;

	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	prime[0] = prime[1] = 0;
	for (i=2; i<n; i++) {
		prime[i] = prime[i-1];
		if (is_prime[i]) {
			prime[i]++;
			int j;
			for (j=i+i; j<n; j+=i)
				is_prime[j] = false;

		}
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);

	init_prime();
	int a;

	while (scanf("%d", &a)==1) {
		printf("%d\n", prime[a]);

	}

	return 0;
}

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

int main()
{
	vector<int> prime,count;
	int j, k, x, num;
	while (cin >> num){
		prime.push_back(2);
		x = 1;
		k = 1;
		while (prime[k-1] <= num)
		{
			x += 2;
			j = 0;
			while (j < k && x % prime[j] != 0)j++;
			if (j == k)
			{
				prime.push_back(x);
				k++;
			}
		}
		count.push_back(prime.size() - 1);
		prime.clear();
	}
	for (int i = 0; i < count.size(); i++)
	{
		cout << count[i] << endl;
	}
	return 0;
}

C++: #include <deque>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
int main(){
	int N,t,f,ans=0,s;
	while(cin>>N){
	for(int j=0;j<N;j++){
		int cnt=0;
		for(int k=2;k<N;k++){
				if(N%k==0){
				cnt=1; 
			}
		}
		if(data[j]==2){
				cnt=0;
			}
		else if(data[j]==1){
				cnt=1;
			}
		if(cnt==0)ans++;
	}
 
cout<<ans<<endl;
}
return 0;
}

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

using namespace std;

int main()
{
    int num;
    while(scanf("%d",&num)<=30){

            int a,b;
            int cot=0;
            for(a=2;a<=num;a++){

                b=0;
                for(int i=2;i<=sqrt(a);i++){
                    if(a%i==0){
                    b=1;
                    break;
                    }
                }
                if(b==0)
                cot++;
            }
            cout << cot << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
#define range 1000000
int total_added = 4;
struct primes{
	 int  key;
	 int  counts;
};
primes p[range];
bool is_prime(int key)
{
	int i;
	for (i = 2; i <= sqrt(key); i++)
	{
		if (key%i == 0)return false;
	}
	return true;
}
void init()
{
	p[0].key = 2;
	p[0].counts = 1;
	p[1].key = 3;
	p[1].counts = 2;
	p[2].key = 5;
	p[2].counts = 3;
	p[3].key = 7;
	p[3].counts = 4;
	int i;
	for (i = 8; i <= range; i++)
	{
		if (i % 2 != 0&&i%3!=0&&i%5!=0)
		{
			if (is_prime(i))
			{
				p[total_added].key = i;
				p[total_added].counts = p[total_added - 1].counts + 1;
				total_added++;
			}
		}
	}
}
int counting_result(int key)
{
	for (int i =total_added-1; i>=0; i--)
	{
		if (key >= p[i].key)
			return p[i].counts;
	}
	return 0;
}

int main()
{
	init();
	int i=0, n;
	while (scanf("%d", &n)==1&&30)
	{
		
		printf("%d\n",counting_result(n));
		i++;
	}

}

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

using namespace std;


int main(){
	int ans=0;
	int n,flag=0;

	while(cin >> n){
		for(int number=2;number<=n;number++){
			for(int i=2;i<number;++i ) {
	    		if( number%i==0 ) {
	      			flag = 1;
	      			break;
	    		}
	  		}
			if(flag==0)ans++;
			flag=0;
		}
		printf("%d\n",ans);
		ans = 0;
	}


	return 0;
}

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

using namespace std;

int main(){
	int n,i,j,buf,cnt;
	bool flag;

	while(cin >> n){
		if(n == 1){
			cout << "0" << endl;
			continue;
		}

		cnt = 1;

		for(i=3;i<=n;i+=2){
			flag = false;
			buf = (int)sqrt((double)i);

			for(j=3;j<=buf;j+=2){
				if((i % j) == 0){
					flag = true;
					break;
				}
			}

			if(flag == false){
				cnt++;
			}
		}

		cout << cnt << endl;
	}

	return 0;
}