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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

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

int main(){
	int n,w=1;
	cin >> n;
	for(int j=n;j>1;j--){
		for(int i=2;i<j;++i){
			if(j%i == 0){
				break;
			}
			if(i==j-1){
//				cout << j << endl;
				w++;
			}
		}
	}
	cout << w;	
	return 0;
}

C++: #include <iostream>
using namespace std;
 
bool IsPrime(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  int prime[1000000]={};
  for(int i=2;i<=1000000;i++){
      if(IsPrime(i)) prime[i]=prime[i-1]+1;
      else prime[i]=prime[i-1];
  }
   
  while(cin >> n) cout << prime[n]<< endl;

   
   return 0;
}

C++: #include<iostream>
#include<string.h>
int main(){int m=1,n=999999,o,c=n/2+1,d;bool*v=new bool[c];for(memset(v,1,c);m<499;m++)for(o=m*2+1,d=o*3;v[m]&&d<n+1;d+=o*2)v[d/2]=0;for(;!(std::cin>>n).eof();printf("%d\n",c))for(c=n-->1,m=1;m<n/2+1;)c+=v[m++];delete[]v;}

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;
}