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++: #include<iostream>
#include<cstdio>
using namespace std;

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(scanf("%d",&n)!=EOF){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

  if(n%2==0)
    return false;

  else{
    for(int i=3; i<n; i++){
      if(n%i == 0)
	return false;
    }
  }

  return true;
}

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

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

const int MAXN = 1000005;
int num[MAXN];

int main() {
  for(int i = 0; i < MAXN; ++i) {
    num[i] = isPrime(i);
  }
  for(int i = 1; i < MAXN; ++i) {
    num[i] += num[i-1];
  }
  int n;
  while(cin >> n) {
    cout << num[n] << endl;
  }
  return 0;
}

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

int main() {
    bool is_prime[N];
    is_prime[0]=is_prime[1]=false;
    for (int i=2; i<N; i++) {
        is_prime[i]=true;
    }
    for (int i=2; i*i<N; i++) {
        if (is_prime[i]) {
            for (int j=i*i; j<N; j+=i) {
                is_prime[j]=false;
            }
        }
    }
    int n[N];
    int count=0;
    for (int i=0; i<N; i++) {
        if (is_prime[i]) {
            count++;
        }
        n[i]=count;
    }
    while (true) {
        int x;
        cin >> x;
        if (cin.eof()) {
            break;
        }
        cout << n[x] << endl;
    }
    return 0;
}

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

int main(){
	int i, j, n, num = 0, count = 0;

	while(cin >> n){
		count = 0;
		for(i = 2; i <= n; i++){
			num = 0;
			for(j = 1; j <= i; j++){
				if(i % j == 0) num ++;
			}
			if(num == 2) count ++;
 		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool IsPrime(int n)
{
	int s = floor(sqrt(n)+0.5);
	for(int i = 2;i<=s;i++)
		if(n%i==0)return false;
	return true;
}
const int maxn = 1000000;
bool ar[maxn];
int dp[maxn];
int main()
{
	for(int i = 2;i<=maxn;i++)
		if(IsPrime(i))ar[i] = true;
	for(int i = 1;i<=maxn;i++)
		if(ar[i])dp[i] = dp[i-1]+1;
		else dp[i] = dp[i-1];
	int n;
	while(cin >> n)
		cout << dp[n] <<endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,i,j;
	int time_sum = 0;
	int a[100000];
	while (cin >> n)
	{
		if (time_sum == 29) break;
		time_sum = time_sum + 1;
		int sum = 0;
		for (i = 2; i <=n; i++)
			a[i] = 1;
		for (i = 2; i <=n; i++)
		{
			if (a[i])
				for (j = i + i; j <=n; j = j + i)
					a[j] = 0;
		}
		for (i = 2; i <=n; i++)
		{
			if (a[i]) sum = sum + 1;
		}
		cout << sum << endl;
	}
	return 0;

}

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


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

C++: #include <iostream>
#include <complex>
int main(){
	while(1){
		int ans=0;
		int n;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			std::cout<<0<<std::endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=11){
				for(int i=11;i<=n;i+=2){
					bool prime=true;
					int iSqrt=sqrt(i);
					for(int k=3;k<=iSqrt;k+=2){
						if(i%k==0){
							prime=false;
							break;
						}
					}
					if(prime)ans++;
				}
			}
		std::cout<<ans<<std::endl;
		}
	}
}

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

int main(){
  bool prime[1000000] = {};
  int sum[1000000]; sum[0] = sum[1] = 0;
  for(int i = 2 ; i < 1000000 ; i++ ){
    sum[i] = sum[i - 1];
    if(!prime[i]){
      for(int j = i + i ; j < 1000000 ; j += i ){
        prime[j] = true;
      }
      sum[i]++;
    }
  }

  int n;
  while(cin >> n){
    cout << sum[n] << endl;
  }
}

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

using namespace std;

vector<int> ps;

int isprime(int n){
	vector<int>::iterator it;
	for(it=ps.begin();it!=ps.end();it++){
		if(n%(*it) == 0) return 0;
	}
	ps.push_back(n);
	return 1;
}

int main(){
	int n;
	scanf("%d", &n);

	int c=0;
	for(int i=2;i<=n;i++)
		if(isprime(i)) c++;

	printf("%d\n", c);
}

C++: #include<stdio.h>

int main(){
	int n,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)==1){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0) p=true;
		}
		if(p) p=false;
		else{
			count++;
			p=false;
		}
	}
	printf("%d\n",count);
	count=0;
		}
	return 0;
	}

C++: #include <iostream>
using namespace std;
int main(){
  const int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;
  int n,c=0,i=0;
  for(cin>>n;i<n;i++)if(prime[i})count++;
  cout<<c<<endl;
  return 0;}

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

#define REP(i, N) for(int i = 0; i < N; i++) 

const int N = 1000 * 1000;
int isPrime[1000 * 1000];

int main() {
  REP(i, N) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0; i < N; i++)
    if( isPrime[i] ) {
      for(int j = i + i; j < N; j += i)
        isPrime[j] = false;
    }

  int n;
  cin >> n;
  int cnt = 0;
  for(int i = 0; i <= n; i++) if( isPrime[i] ) cnt++;
  cout << cnt << endl;
}

C++: #include<iostream>
using namespace std;
int main(){
	long long n,i,j,k,sum=0,num,SUM=0;
	for(i=0;i<30;i++){
		cin>>n;
		for(j=1;j<=n;j++){
			for(k=j;k>=1;k--){
				num=j/k*k;
				if(num==j)sum++;
			}
			if(sum==2)SUM++;
			sum=0;
		}
		cout<<SUM<<endl;
		SUM=0;
	}
	return 0;
}

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

int pn[1000000] = { 1, 1, 0 };

int main(){
	for (int i = 2; i < 1000000; i++){
		if (pn[i] == 1) continue;
		for (int j = i * 2; j < 1000000; j += i){
			pn[j] = 1;
		}
	}
	
	int n;

	while (cin >> n){
		int c = 0; 
		for (int i = 0; i <= n; i++){
			if (pn[i] == 0)
				c++;
		}
		cout << c << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int isPrime[1000001];
int main(){

  fill(isPrime,isPrime+1000001,1);
  isPrime[0]=isPrime[1]=0;
  for(int i = 2 ; i*i < 1000001 ; i++ ){
    if(isPrime[i])for(int j=i*2 ; j < 1000001 ; j+=i)isPrime[j]=0;
  }
  int n;
  while(cin >> n,n){
    int cnt = 0;
    for(int i = 2 ; i <= n ; i++ ){
      if(isPrime[i])cnt++;
    }
    cout << cnt << endl;
  }
}

C++: #include <stdio.h>

int isPrime(int n)
{
	int i;

	if (n == 2)
		return 1;
	for (i = 3; i < n; i+=2) {
		if (n % i == 0) {
			return 0;
		}
	}
	return 1;
}

int main()
{
	int i, n, sum = 0;

	scanf("%d", &n);

	for (i = 2; i <= n; i++) {
		if (isPrime(i))
			sum++;
	}
	printf("%d\n", sum);
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=j;i+=2){
				if(j%i==0)k++;
		        }
		     if(k==1)kk++;
		   }
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<"1"<<endl;
		else cout<<kk+1<<endl;
	   }
	return 0;
	}