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 <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 int n, i, j, k;
 int b;
 int count = 0;
 
 

 while(cin >> n){
  int a[n+1];
  for(i = 2;i < n+1;i++){
    a[i] = i;
  }


  for(i = 2;i*i < n+1;i++){
    if(a[i] != 0){
      b = a[i];
     }
    for(j = 2;j*b < n+1;j++){
      a[j*b] = 0;
    }
  }
  for(i = 2;i < n+1;i++){
    if(a[i] != 0){
      count++; 
    }
  }
  cout << count << endl;
  count = 0;
  
  
 }

 return 0; 
}

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


using namespace std;

int main(){
	int n;
	
	while(cin>>n){
		vector<int> prime(n);
		int ptr=0;
		if(n<=3){
		switch(n){
		case 0:
		case 1: ptr=0; break;
		case 2: ptr=1; break;
		case 3: ptr=2; break;
		}
		}
		else{
			prime[ptr++]=2;
			prime[ptr++]=3;
		
		for(int no=5;no<=n;no+=2){
			int flag=0;
			for(int i=1;prime[i]*prime[i]<=no;i++){
		if(no%prime[i]==0){
				flag=1;
				break;
		}
	}
	if(!flag)
		prime[ptr++]=no;
	}
		}
		cout<<ptr<<endl;
	}
	
	
	
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

int main()
{
	int n;

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

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