Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool flag[10000001];
 
int main(){
    int n=0,ans=0;
    for(int i=0;i <= 1000000;i++){
        if(i<=1)flag[i]=false;
        else flag[i]=true;
    }
    for(int i=2;i <= 1001 ;i++){
        if(flag[i]==true){
            for(int j=i*2 ; j<=1000000 ; j=j+i){
                flag[j] = false;
            }
        }
    }
    while(cin>>n){
        ans=0;
        for(int i=0;i <= n;i++){
            if(flag[i]==true){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<stdio.h>
#include<math.h>
int main(){
	int n,c,i,j,k;
	while(scanf("%d",&n)!=EOF){
		c=1;
		for(j=3;j<=n;j+=2){
			k=1;
			i=3;
			while( i <= sqrt(j) ){
				if(j%i==0){
					k=0;
					break;
				}
				i = i + 2;
			}
			if(k){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

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


int main(){
	bool work[MAX + 1];
	int num, ans = 0;

	// 初期化
	for(int i = 6; i <= MAX; i++){
		for(int j = 2; j < (i / 2); j++){
			if (i % j == 0){
				work[i] = false;
				break;
			}else{
				work[i] = true;
			}
		}
	}
	work[0] = false;
	work[1] = false;
	work[2] = true;
	work[3] = true;
	work[4] = false;
	work[5] = true;

	// 出力
	while(cin >> num){		
		for(int i = 0; i <= num; i++){
			if(work[i] == true){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

C++: ///bismillah_hir_rahmanir_rahim
///GALIB-2015331528

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

int prime[1000000];
int main()
{
    int n,c;
    cin>>n;
    if(n==1){
        cout<<"0"<<endl;
        return 0;
    }

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

    cout<<c<<endl;




    return 0;
}

C++: #include<stdio.h>

bool p(int a){
	if(a==2)return true;
	if(a<2||a%2==0)return false;
	for(int i=3;i*i<=a;i+=2){
		if(a%i==0)return false;
	}
	return true;
}

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

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 0;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 0;
		
		for (int i = 1;i<=num;i++) {
		if(i%2==0) {
			//cout <<"2: "<<i<<endl;
			count ++;
			continue;
		}
		if(i==5||i==7) continue;
		for (int j=9;j<(int)sqrt(i)+1;j=j+2) {
			if (i%j==0) {
				count ++;
				//cout <<"i: "<<i<<" j: "<<j<<endl;
				break;
			}
		}
	}
	cout << (num-count) <<endl;
	//cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,sum;
    int b[999999];
    b[0]=0;
    for(int i=1;i<999999;i++){
        b[i]=prime(i);
    }
    while ( cin >> a){
        sum =0;
        for (int i=0;i<a;i++){
            sum +=b[i];
        }
        cout << sum-1 << endl;
    }
}


int prime(int x){
    if(x==2 || x==3 || x==5 || x==7)
        return 1;
    if(x%2==0 || x%3==0)
        return 0;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 0;
    }
    return 1;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
int p(long x)
{
    long i,j=sqrt(x),k=1;
    for(i=2;i<=(j);i++)
    {
        if(x%i==0){
            k=0;
            //return k;
        break;

        }
    }
    if(k==1)return 1;
    else return 2;
}
using namespace std;
int main()
{
    double a,b,c,i,n,s=0;
    i=1;

    while(i){
        if(i>=30)break;
        cin>>n;
        s=0;
    //a=sqrt(n);
    for(i=2;i<=n;i++)
    {
        if(p(i)==1){s++;}
    }
    cout<<s<<endl;
    i++;
    }


    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>

using namespace std;

int n, ct = 0;
bool p[1000001];

int main(){
	for (int i = 0; i < 1000001; i++) p[i] = 1;
	for (int i = 2; i < 1000; i++){
		if (p[i] == 1){
			for (int j = 0; i*(j + 2) < 1000000; j++){
				p[i*(j + 2)] = 0;
			}
		}
	}
	while (cin >> n){
		for (int i = 2; i < n + 1; i++)
			if (p[i] == 1) ct++;
		cout << ct << endl;
		ct = 0;
	}
}

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

int main(){
    vector<int> ns;
    int temp, max_n = 0;
    while(cin >> temp){
        ns.push_back(temp);
        max_n = max(temp, max_n);
    }
    max_n++;

    vector<bool> is_prime(max_n, true);
    vector<int> primes;
    for(ll i=2;i<max_n;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(ll j=i*i;j<max_n;j+=i){
                is_prime[j] = false;
            }
        }
    }

    for(int n: ns){
        int ans = upper_bound(primes.begin(), primes.end(), n) - primes.begin();
        cout << ans << endl;
    }

    return 0;
}

C++: #include<stdio.h>


int main(){
	int n;
	bool data[1000000];

	int i,j;
	data[0]=data[1]=0;
	for(i=2;i<1000000;i++){
		data[i]=1;
	}

	for(i=0;i<1000000;i++){
		if(data[i]==1){
			for(j=i+i;j<1000000;j=j+i){
				data[j]=0;
			}
		}
	}


	while(scanf("%d",&n)!=EOF){
		j=0;
		for(i=0;i<n+1;i++){
			if(data[i]==1)j++;
		}
		printf("%d\n",j);
	
	}
	return 0;
}

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

int is_it_primeNum(int n)
{
	int a = 1;
	if (n == 0 || n == 1)
		return 0;
	else if (n == 2)
		return 1;
	else if(n % 2 == 0)
		return 0;
	else{ 
		for(int i=3;i<n/2;i+=2){
			if (n%i==0){
				a = 0;
				break;}
		}
	}
	return a;
}
int how_much_primeNum(int n)
{
	int ans = 0;
	for(int i=2;i<=n;i++){
		ans += is_it_primeNum(i);
	}
	return ans;
}

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

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

int main() {
	int n;
	int cnt = 0;
	while(cin >> n) {
		cnt++;
	}
	if(cnt > 1000)
		abort();
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX_N 999999
int main()
{
    int n;
    map<int,bool>notPrime;
    map<int,int>count;
    for (int i = 2 ; i <= MAX_N ; i++)
    {
        if (!notPrime[i])
        {
            for (int g = i+i ; g <= MAX_N ; g += i)
            {
                notPrime[g] = true;
            }
        }
    }
    int cnt = 0;
    count[1] = 0;
    for (int g = 2 ; g <= MAX_N ; g++)
    {
        if (!notPrime[g])
            cnt ++;
        count[g] = cnt;
    }
    while (cin >> n)
    {
        cout << count[n] << endl;
    }
    
}