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 n, ans = 0;
    bool judge = true;
    while(cin >> n){
        for(int i = 2; i <= n; i++){
            for(int j = 2; j < i; j++){
                if(i % j == 0){
                    judge = false;
                    break;
                }
            }
            if(judge)
                ans++;
            else
                judge = true;
        }
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}

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

int main()
{
	int n, x = 0;
	int countdata[1000];
	while (cin >> n) {
		int count = 0;
		for (int a = 2; a <= n; a++) {
			if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a % 7 != 0 || a==2 || a==3 || a==5 || a==7) {
				count++;
			}
		}
		countdata[x] = count;
		x++;
	}
	for (int a = 0; a < x; a++) {
		cout << countdata[a] << endl;
	}
}

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

int main(void) {
    int N=999999;
    int p[N] , s[N];
    p[0]=0;
    for (int i=1; i<N; i++){
        p[i] = 1;
        s[i] = 0;
    }
    for (int i=1; i<N; i++){
        if (p[i]==1){
            int n=i+1 , m=2*n;
            while (m<=N){
                p[m-1] = 0;
                m += n;
            }
        }
    }
    
    for (int i=1; i<N; i++){
        s[i] = s[i-1]+p[i];
    }
    int n;
    while (1){
        cin >> n;
        cout << s[n-1] << endl;
    }
    return 0;
}

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

int whether(int num);
int count(int num);

int main(){
	int n=1;
	int a=0;

	while(a==n){
	scanf("%d",&n);
	a = count(n);
	printf("%d\n",a);
	a=n;
}
	return 0;
}

int whether(int num){
	int s=sqrt(num);
	int i;
	for(i=3; i<=s; i+=2){ if(num%i==0) return 0; }

	return 1;
}

int count(int num){
	int a=1;
	int i;
	if(num <2){ return 0; }
	for(i=3; i<=num; i+=2){
		a += whether(i);
	}

	return a;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int maxn=1e6;
#define ll long long
int pri[maxn];int vis[maxn];int rec[maxn];int op=0;int t;
void advan(){
     vis[1]=1;
     for(ll i=1;i<=1e6;i++){
        rec[i]=op;if(vis[i])continue;
        vis[op++]=1;rec[i]=op;
        for(ll j=i*i;j<1e6;j=j+i){
            vis[j]=1;
}}}
int main(){
    advan();int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",rec[n]);
    }
}

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

bool sieve[1000000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=0;i<n;i++)
		{
			ans+=sieve[i]?1:0;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	memset(sieve,-1,sizeof(sieve));
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<1000000;i++)
	{
		for(int j=i*2;j<1000000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

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

using namespace std;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        if(isprime(i)) ++cnt;
    }
    cout<<cnt<<endl;
}

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

using namespace std;


vector<int> era(int n){
	vector<int> prime;
	bool *is_prime = new bool[n+1];
	fill(is_prime,is_prime+n+1,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j = i*2; j <= n; j+=i){
				is_prime[j] = false;
			}
		}
	}
	delete []is_prime;
	return prime;
}

int main(){

	int n;
	cin >> n;

	vector<int> p = era(n);
	cout << p.size() << endl;

	return 0;
}

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

#define Max 1000000

int prime [10000000];

int main()
{
	int n, out;

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

	while (cin >> n){
		out = 0;
		for (int i = 0; i <= n; i++){
			if (prime[i] == 0) out++;
		}
		cout << out - 2 << endl;
	}
	return(0);
}

C++: #include<iostream>
using namespace std;
int d[1000000];
int main(){
	int n;
	for(int i=0;i<1000000;i++)
	d[i]=0;
	d[0]=1;
	d[1]=1;
	for(int i=2;i*i<1000000;i++){
		if(d[i]==0){
			for(int j=2;i*j<1000000;j++){
				if(d[i*j]==0)
					d[i*j]=1;
			}
		}
	}
	int ans;
	while(cin>>n,n){
		ans=0;
		for(int i=0;i<=n;i++){
			if(d[i]==0)
			ans++;
		}
		cout<<ans<<endl;;
	}
	return 0;
}

C++: #include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];//t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j] = true;
		}
		}
		t[i]=t[i-1]+!c[i];
	}
	/*for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}*/
	for(int n;scanf("%d", &n);n++){
		printf("%d\n", t[n]);
	}
	return 0;
}

C++: #include<stdio.h>

int s[1000000] = {0};

int main(){
	int a,b,c,d,e;
	int temp;
	int cont = 0;
	
	while(scanf("%d",&a) != EOF){
		/*
		for(int i = 0; i < a; i++){
			s[i] = 1;
		}
		*/
		
		cont = 0;
		
		s[0] = 1;
		s[1] = 1;
		
		for(temp = 2; temp < a; temp++){
			if(s[temp] == 0){
				for(b=temp; b < a; b+= temp){
					if(b == temp){
						s[b] = 0;
					}
					else{
						s[b] = 1;
					}
				}
			}
		}
		
		for(c = 0; c < a; c++){
			if(s[c] == 0){
				
	//		printf("%d\n",c);
				cont++;
			}
		}
		
		printf("%d\n",cont);
	}
}

C++: #include<iostream>
using namespace std;
#define REP(i,n) for(unsigned int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define MAX 100001

bool N[MAX] = {};

int M[MAX] = {};

void SoE()
{
	REP(i, MAX)N[i] = true;

	N[1] = true;
	for (unsigned int i = 2; i*i <= MAX; i++)
	{
		for (unsigned int j = i+i; j < MAX; j += i)
		{
			N[j] = false;
		}
	}
}

void Count()
{
	M[1] = 0;
	FOR(i, 2, MAX - 1)
	{
		int add = 0;
		if (N[i] == true)
		{
			add = 1;
		}
		M[i] = M[i - 1] + add;
	}
}

int main()
{
	SoE();
	Count();
	int tmp;
	while (cin >> tmp)
	{
		cout << M[tmp] << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;

vector<int>primenumber;
int d[1050000];

int main()
{
	int n;
	
	primenumber.push_back(2);
	d[2] = 1;

	int maxn = 0;

	while (cin >> n) {
		if (maxn<n) {
			for (int i = max(maxn+1,3); i <= n; i++) {
				int ope = 1;
				for (int j = 0; j < primenumber.size(); j++) {
					if (primenumber[j] * primenumber[j] > i)break;
					if (i%primenumber[j] == 0) {
						ope = 0;
						break;
					}
				}
				if (ope == 1)primenumber.push_back(i);
				d[i] = primenumber.size();
			}
			maxn = n;
		}
		cout << d[n] << endl;
	}
	
	return 0;
}

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