Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		flag := false
		count := 0

		for i := 3; i <= num; i += 2 { //1を除く入力値以下の数字
			for j := 3; j < i; j += 2 {
				if i%j == 0 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count + 1)
	}
}

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

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	int i = 2;
	while (i <= num) {
		if (i == 2) {
			count++;
			i++;
			continue;
		}
		else if (i % 2 == 0) {
			//count++;
			i++;
			continue;
		}
		else {
			// Route Num?????´??°??¨??????????????????
			int routeN_int = (int)sqrt(i);
			int j = 3;
			while (1) {
				if (j > routeN_int) {
					count++;
					break;
				}
				if (i % j == 0) {
					break;
				}
				j += 2;
			}
		}
		i++;
	}


	return count;
}

int main() {

	int num = 0;
	while (cin >> num, num != 0) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

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

bool IsPrime(int i){
    if(i < 2) return false;
    else if(i == 2) return true;
    else if(i % 2 == 0) return false;

    double sqrtNum = sqrt(i);
    for(int j = 3; j <= sqrtNum; j += 2){
        if(i % j == 0){
            return false;
        }
    }

    return true;
}

int main(){
    int n;
    while(cin >> n){
        int k = 0;
        for(int i = 0; i <= n; ++i){
           if(IsPrime(i) == true){
               k++;
           }else ;
        }
        cout << k << endl;
    }
}