Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

C++: #include <iostream>
#include <stdio.h>
using namespace std;
void init(bool* table){
	for (int i = 2; i < 100000; i++){
		for (int j = 2; j < 100000/i; j++){
			*(table + i*j) = false;
		}
	}
}
int main(){
	int num;
	bool table[100000];
	for (int i = 0; i < 100000; i++){
		table[i] = true;
	}
	init(table);
	while (cin >> num){
		int cnt = 0;
		for (int i = 2; i <= num; i++){
			if (table[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//?????§??¬?´???°??¨????°???¬?????°
//O(1)?????????
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

#define NUM_MAX   1000010
bool flag[NUM_MAX];
vector< int >prm;

int N;
int ans = 0;
int K;

void eratosthenes(){
	if( N < 2 ) return;
	fill( flag, flag+NUM_MAX, 0 );
	int idx = 2;
	while( idx <= K ){
		while( flag[idx] ) idx++;
		if( idx > N ) break;
		//prm.push_back( idx );
		for( int i = idx; i <= N; i += idx ) flag[i] = 1;
		ans++;
	}
	while( idx < N ){
		idx++;
		if( !flag[idx] ){
			//prm.push_back( idx );
			ans++;
		}
	}
}


int main(){
	
	while( scanf("%d", &N) != EOF ){
		K = sqrt( N );
		K++;
		
		eratosthenes();
		
		cout<<ans<<endl;
		/*
		REP( i, prm.size() ){
			cout<<prm[i]<<endl;
		}*/
		//prm.clear();
		ans = 0;
	}	
	return 0;
	
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
while(cin >> n,!cin.eof()){
vector<int> prime;
prime.push_back(2);//ôðÈ­½ß2ÍÅÉüêÄ¨­
bool flag;
for(int x=3;x<=n;x+=2){
flag=true;
for(int y=0;prime[y]*prime[y]<=x;y++){
if(!(x%prime[y])){
flag=!flag;
break;
}
}
if(flag)prime.push_back(x);
}
int r = (n<=1)?(0):(prime.size());
cout << r << endl;
prime.clear();
}
return 0;
}

C++: #include<cstdio>
#include<string.h>
using namespace std;
int pNum;
bool IsPrime[1000010];
int Prime[1000010];
int GetPrime(int n){
    memset(IsPrime,true,sizeof(IsPrime));
    IsPrime[0]=IsPrime[1]=false;
    pNum=0;
    for(int i=2;i<=n;i++){
        if(IsPrime[i])Prime[++pNum]=i;
        for(int j=1;j<=pNum&&Prime[j]*i<=n;j++){
            IsPrime[Prime[j]*i]=false;
            if(i%Prime[j]==0)break;
        }
    }
    return pNum;
}
int main(){
    int n;
    while(scanf("%d",&n)){
        printf("%d\n",GetPrime(n));
    }
    return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	bool flag[1000000];
	int p;

	for( int i = 0;i < 1000000;i++ ) flag[i] = true;

	for( int i = 2;i <= sqrt( 1000000 );i++ ){
		if( flag[i] != false ) for( int j = 2;j * i < 1000000;j++ ) flag[j * i] = false;
	}

	while( cin >> p ){
		int count = 0;
		for( int i = 2;i <= p;i++ ) if( flag[i] ) count++;
		cout << count << endl;
	}
}

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

void SieveOfEratosthenes(int n)
{
    int c = 0;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
       if (prime[p]){
            c++;
       }

       cout<<c<<endl;

}

// Driver Program to test above function
int main()
{
    int n;
    while(cin>>n)
    {
        SieveOfEratosthenes(n);
    }

    return 0;
}