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>
#include <vector>
#define pb(a) push_back(a) 
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
 
int main() {
    int n = 1000000;
    vector<int> v;
    v.pb(2);
    for(int i=3;i<=n;i+=2) {
        bool add = true;
        rep(j,0,v.size()) {
            if(v[j] * v[j] > i) break;
            if(i % v[j] == 0) {
                add = false; 
                break;
            }
        }
        if(add) v.pb(i);
    }

    int m;
    while(cin >> m) {
        cout << upper_bound(v.begin(), v.end(), m) - v.begin() << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int prime[1000000];
int Prime_creat()
{
    int i,j;
    for(i=2;i<=1000000;i++)
    {
        if(prime[i])
        {
            for(j=i+i;j<=1000000;j+=i)
            prime[j]=0;
        }
    }
}
int main()
{
    int i,n,ans;
    memset(prime,1,sizeof(prime));//  1是素数 0不是素数
    Prime_creat();
    while(scanf("%d",&n)!=EOF)
    {
        ans=0;
        for(i=2;i<=n;i++)
        {
            if(prime[i])
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

int A[1000000];
int Eratosthenes(int n)
{
	int mama = 0;
	for (int i = 0; i < n; i++)
	{
		A[i] = 1;
	}
	for (int i = 2; i < sqrt(n); i++)
	{
		if (A[i])
		{
			for (int j = 0; i*(j + 2) < n; j++)
			{
				A[i*(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < n; i++)
	{
		if (A[i])
		{
			mama++;
		}
	}
	return mama;
}

int main()
{
	int n;

	while ((scanf("%d",&n))!= -1)
	{
		printf("%d\n", Eratosthenes(n+1));
	}
	return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int cnt=0;
		vector<bool> v(n+1,true);
		for(int i=2; i<=sqrt(n); i++){
			if(v[i]){
				for(int j=i+1; j<=n;j++){
					if(j%i==0)
						v[j]=false;
				}
			}
		}
		for(int i=2;i<=n;i++){
			if(v[i]==true)
				cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include<stdio.h>

int main(){
  const int MAX_V = 1000000;
  int prime[MAX_V+1];
  int i, k, v;
  int ans;
  for(i = 2; i <= MAX_V; i++){
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++){
    if(prime[i]){
      for(k = 2 * i; k <= MAX_V; k += i){
        prime[k] = 0;
      }
    }
  }
  while(scanf("%d", &v) != EOF){
    int count = 0;
    for(k = 2; k <= v; k++){
      ans = prime[k];
      if(ans == 1){
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

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

/* {{{ */
#define PI(N) ((M_PI * (N)) / 180) //?§???????????????¢??????????????????
#define CL(N) (cout << (N) << endl)
#define DCT(N) (cout << "debug " << (N) << endl)
#define REP(i, N) for (int i = 0; i < (N); i++)
/* }}} */

bool f[1000001] = {false};

int main()
{
	for (int i = 2; i * i < 1000001; i++){
    	for (int j = i * i; j < 1000001; j += i){
            f[j] = true;
        }
    }

	int n;
    while (cin >> n){
        int c = 0;
        for (int i = 2; i <= n; i++){
            if (!f[i])c++;
        }
        CL(c);
    }

	return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
 
int main(){
int unti[100001] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
    if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt ;
    }
 
 
}

C++: #include<bits/stdc++.h>
using namespace std;
bool pr[1000005];
int a[1000005] = {0, 0};
int main()
{
    memset(pr, true, sizeof(pr));
    for (int i = 2; i < 1000; i++)
        if (pr[i])
            for (int j = i * 2; j < 1000000; j += i)
                pr[j] = false;
    for (int i = 2; i < 1000000; i++)
        if (pr[i])
            a[i] = a[i - 1] + 1;
        else
            a[i] = a[i - 1];
    int n;
    while (~scanf("%d", &n))
        printf("%d\n", a[n]);
    return 0;
}

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

int main()
{
	unsigned int  n,j;
	cin >> n;
	unsigned  int num,count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(j = 2; j <=num; j++)
		{
			if((num % j) == 0)
			{
				break;
			}
		}
		if(j == num) count++;
	}
	cout << count << endl;
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void init(){
	for(int i=2;i<999999;i++){
		bool isprime=true;
		for(vector::iterator p(prime.begin());p!=prime.end();p++){
			if(i%*p==0){
				isprime=false;
				break;
			}
		}
		if(isprime){
			prime.push_back(i);
		}
	}
}
int main(){
	int n;
	init();
	while(cin>>n){
		cout<<lower_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int main() {
	int n,u,v,sum;
	double t;
	while (cin >> n) {
		sum = 0;
		for (int i = 1; i <= n; i++) {
			v = 0;
			t = sqrt(i) / 2;
			if (i > 7 && (i % 2 == 0 || i % 3 == 0 || i % 5 == 0)) {
				sum += 0;
			}
			else {
				for (int j = 0; j <= t; j++) {
					u = 2 * j + 1;
					if (i%u == 0) {
						v += 1;
					}
				}
			}
			while (v == 1) {
				sum += 1;
				break;
			}
		}
		if (n > 3) {
			cout << sum - 2 << endl;
		}
		else if(n==2||n==3) {
			cout << n-1 << endl;
		}
		else if (n == 1) {
			cout << 0 << endl;
		}
	}
	return 0;
}

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

using namespace std;


int main(){

	int i, j, k;
	int n;

	while(cin >> n){

		int count = 0;

		if(n>2){
			count ++;
			for(i=3 ; i<=n ; i+=2){
				for(j=3 ; j<=i ; j+=2){
					k = i % j;
					if(k == 0) break;
				}
				if(j == i) count ++;
			}
		}
		cout << count << endl;

	}


	return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int data,i=0,j=2,k=0,l=0,kai[100]={0},s[100000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<0)break;
		else if(data=1)
		{
			kai[k]=0;
		}
		else
		{
			for(i=2;i<data;i++)
				s[i]=i;
		
			for(i=2;i*2<data;i++)		
			{
				for(j=2;j*i<data;j++)				
					s[j*i]=0;
			}
			for(i=2;i<data;i++)
			{	
				if(s[i]!=0)
				{
					l+=1;
				}
			}
		}
		kai[k]=l;
		k+=1;
	}

  for(j=0;j<k;j++)
    printf("%d\n",kai[j]);
  return 0;
}

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

bool prime[1000001];

void era(){
	for(int i=2;i<1000000;i++)prime[i]=true;
	for(int i=2;i*i<1000000;i++){
		if(prime[i]==true){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=0;
			}
		}
	}
}

int main(){
	era();
	int n,ans;
	while(cin>>n){
		ans=0;
		for(int i=0;i<n;i++){
			if(prime[i]==1)ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    ll n;
    while(cin>>n){
        vector<bool> ip;
        if(ip.size()<n+1){
            ip.resize(n+1,true);
        }
        ip[0]=false;
        ip[1]=false;
        for(int i=2;i<(n+1)/2;i++){
            for(int j=2;i*j<n+1;j++){
                ip[i*j]=false;
            }
        }
        ll ans=0;
        for(int i=0;i<n+1;i++){
            if(ip[i])ans++;
        }
        
        
        cout<<ans<<endl;
        
        
        
    }





return 0;
}