Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: //--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

bool is_prime(int a) {
	int now = 2;
	while (now*now <= a) {
		if (a%now == 0)return 0;
		else now++;
	}
	return 1;
}


int main() {
	while (cin >> n) {
		ll ans = 0;
		bool a[1000001];
		for (int i = 2; i <= n; i++) {
			if (a[i] == 1)continue;
			if (is_prime(i))ans++;
			else {
				for (int j = i; j <= n; j += i) {
					a[j] = 1;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main()
{
    int n, j, sum = 0, flag = 0;


    while(scanf("%d", &n) == 1)
    {
        for(j = 2; j <= n; j++)
        {
            if(j % 2 == 0 && j != 2)
            {
                flag = 1;
            }
            else if(j % 3== 0 && j != 3)
            {
                flag = 1;
            }
            else if(j % 5== 0 &&  j != 5)
            {
               flag = 1;
            }
            else if(j % 7 == 0 && j != 7)
            {
               flag = 1;
            }
            if(flag == 0)
            {
                sum = sum + 1;
            }
            flag = 0;

        }
        printf("%d\n", sum);
        flag = 0;
        sum = 0;
    }
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	vector<int> prime;
	
	for (int i = 3; i < 10000000; i += 2){
		int j;
		for (j = 1; j < prime.size(); j++){
			if (i % prime[j]){
				break;
			}
		}
		if (j >= prime.size()){
			prime.push_back(i);
		}
	}
	while (scanf("%d", &n) != EOF){
		int count;
		
		for (count = 1; prime[count - 1] < n; count++);
		if (n >= 2){
			count++;
		}
		printf("%d\n", count);
	}
	
	return 0;
}

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

#define MAX 1000000

int main()
{
	int n;
	int prime[MAX];

	prime[0] = prime[1] = false;

	for (int i = 2; i < MAX; i++){
		prime[i] = true;
	}

	for (int i = 0; i < MAX; i++){
		for (int j = i * i; j < MAX; j += i){
			prime[j] = false;
		}
	}

	for (int i = 0; i < MAX; i++){
		prime[i + 1] += prime[i];
	}

	while (scanf("%d", &n) != EOF){
		printf("%d\n", prime[n]);
	}

	return (0);
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> prime_list;
  bool flag;

  prime_list.push_back(2);
  for (int i = 3; i < 50; i++) {
    for (int j = 0; j < prime_list.size(); j++) {
      if(i%prime_list[j] == 0) {
        flag = false;
        break;
      } else {
        flag = true;
      }
    }
    if (flag) {
      prime_list.push_back(i);
    }
  }

  int data, count;
  while(cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] <= data; i++, count = i);
    cout << count << endl;
  }
}

C++: #include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
	int max,n[1000],c = 0,check;
	while(cin >> max){
		c = 0;
		for(int i = 2;max >= i;i++){
			check = 0;
			for(int iii = 1;c >= iii;iii++){
				if(i % n[iii] == 0){check = 1;break;}
			}
			for(int ii = 2;i > ii and check == 0;ii++){
				if(i % ii == 0){check = 1;break;}
			}
			if(check == 0){c++;n[c] = i;}

		}
		cout << c << endl;
	}



}

C++: #include <stdio.h>

#define MAX (100000)

int main(void)
{
	int prime[MAX + 1] = {1};
	int n;
	int ans;
	int i;
	
	for (int i = 0; i <= MAX; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	i = 0;
	while (i * i <= MAX){
		while (prime[++i] != 1 && i * i <= MAX);
		//printf("%d ", i);
		for (int j = 2; j * i <= MAX; j++){
			//printf("%d\n", i * j);
			prime[i * j] = 0;
		}
	}
	
	scanf("%d", &n);
	
	ans = 0;
	for (int i = 2; i <= n; i++){
		if (prime[i] == 1){
			ans++;
		}
	}
	
	printf("%d\n", ans);
	
	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;
		}
		for (int j=3;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 <bits/stdc++.h>
using namespace std;

vector<int> sieve_of_eratosthenes(int n) {
    vector<int> prime(n + 1, 0);
    for (int i = 2; i <= n; ++i) prime[i] = i;
    for (int i = 2; i * i <= n; ++i) {
        if (prime[i]) {
            for (int j = i * i; j <= n; j += i) prime[j] = 0;
        }
    }
    // prime.erase(remove(begin(prime), end(prime), 0), end(prime));
    return prime;
}

int main() {
    auto prime = sieve_of_eratosthenes(1e6);
    for (int n; cin >> n;) {
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,n;
    n=0;
    while ( cin >> a){
        for (int i=2;i<a;i++){
            if (prime(i)==0){
                n++;
            }
        }
        cout << n << endl;
    }
}


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

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while (scanf ("%d",&n)!=EOF)
    {
    int prime[n+1],i,j;
    for (i=0;i<=n;i++)
        prime[i]=1;
    prime[0]=0;
    prime[1]=0;
    for (i=2;i<=sqrt(n);i++)
    {
        if (prime[i]==1)
        {
            for(j=2;i*j<=n;j++)
                prime[i*j]=0;
        }
    }
    int cnt=0;
    for (i=0;i<=n;i++)
    {
        if (prime[i]!=0)
            cnt++;
    }
    cout<<cnt<<endl;
    }
}