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 <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

vector<long long> primelist(long long n){
  vector<bool> prime(n+1,1);
  for(long long i = 2;i <= n;i++){
    if(prime[i]){
      for(long long j = 2*i;j <= n;j += i){
        prime[j] = 0;
      }
    }
  }
  prime[0] = 0;
  prime[1] = 0;
  vector<long long> primelist;
  for(long long i = 0;i <= n;i++)if(prime[i])primelist.pb(i);
  return primelist;
}

signed main(){
  int n;
  while(cin >> n){
    cout << primelist(n).size() << endl;
  }
}

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

using namespace std;

typedef long long ll;

int main()
{
	ll n;
	vector<ll> pl;
	back_insert_iterator<vector<ll> > it(pl);
	
	while(cin>>n){
		//ú»
		pl.clear();
		//nª2ÈºÌÆ«Ì
		if(n < 2){
			cout<<0<<endl;
			continue;
		}
		//â¿Ìì¬
		*it = 2;
		for(ll i = 3; i <= sqrt((long double)n); i++){
			for(ll t = 0; t < pl.size(); t++){
				if(i % pl[t] == 0) break;
				if(t == pl.size() -1) *it = i;
			}
		}
		//â¿É©¯é
		int L = pl.size();
		for(ll i = sqrt((long double)n) +1; i <= n; i++){
			for(ll t = 0; t < L; t++){
				if(i % pl[t] == 0) break;
				if(t == L -1) *it = i;
			}
		}
		cout<< pl.size() <<endl;
	}
}

C++: #include<iostream>
using namespace std;
bool arr[1000000];
int main()
{
	int n,p;
	cin>>n;
  	for(int i=2;i<=1000000;i++){
		if(arr[i]==0)
		{
		    p=i;
			for (int j=2;p*j<=1000000;j++)
			{
				arr[p*j]=1;
			}
		}
	}
	int count=0;
	for(int i=2;i<=n;i++){if(arr[i]==0)count++;}
	cout<<count<<endl;
	delete[] arr;
	return 0;
}

C++: #include <cstdio>

long MAX=999999;

int main(void){
    long int s[1000000]={0},k=0,i,j,n;
    
    for(i=2;i<=MAX;i++){
        if( !s[i] ){
            k++;
            for(j=2;j*i<=MAX;j++){
                s[j*i]=-1;
            }
        }
        s[i]=k;
    }
    
    
    while(EOF != scanf("%ld",&n)){
        printf("%ld\n",s[n]);
    }
    
    
    return 0;
}

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

bool mark [1000000];
 void sieve ()
 {
    int N = 1000000;
    memset (mark, true, N + 2);

    mark [0] = mark [1] = false;

    for ( int i = 4; i < N + 2; i += 2 )
        mark [i] = false;

    for ( int i = 3; i * i <= N + 2; i += 2 ) {
        if ( mark [i] == true ) {
            for ( int j = i * i; j < N + 2; j += 2 * i )
                mark [j] = false;
        }
    }
 }
int main()
{
    int n;
    sieve();
    while(scanf("%d",&n)!=EOF){
        int count = 0,i;
        for(i=2;i<=n;++i)
        {
            if(mark[i]==true)
                count++;
        }
        printf("%d",count);
   }
}

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


int main() {

//変数の宣言

	int i,n,j,sum,judge=1;
	
	while(cin>>n){
		sum = 1;
		for(i=3;i<n+1;i+=2){
			for(j=3;j<=sqrt(i);j+=2){
				if(i%j==0){
					judge = 0;
					break;
				}
			}
			if (judge==1){
				sum++;
			}
			judge = 1;
		}
		
		cout << sum <<endl;
	}

	return 0;
}

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

int main(){
	const int max_num=10000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

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

	return 0;
}

C++: #include	<stdio.h>

bool isPrimeNumber(int number){
	if(number	  == 2)	return true;
	if(number % 2 == 0)	return false;
	
	for(int i = 3; i <= sqrt(number) ;i += 2){
		if(number % i == 0)	return false;
	}
	
	return true;
}

int main(int argc, char** argv){
	
	int search, counter;
	
	while((scanf("%d", &search)) != EOF){
		counter = 0;
		for(int i = 2; i <= search; i++){
			counter += isPrimeNumber(i) ? 1 : 0;		
		}
		printf("%d\n", counter);
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <functional>

static int const MAX(1000000);

class Mod{
	const int n;
	public:
		Mod(const int _n):n(_n){}
		bool operator()(const int _src){
			return ! (_src % n);
		}
};

const std::vector<int> Eratosthenes(std::set<int>& src){
	std::vector<int> result;
	int cnt(0);
	while(!src.empty()){
	  int n(*src.begin());
		result.push_back(n);
		Mod mod(n);
		//std::set<int>::iterator it= std::remove_if( src.begin(), src.end(), mod );
		// n>(MAX/2) ? std::remove( src.begin(), src.end(), n ) :
		for(int i(n);i<MAX;i+=n)  {
		std::set<int>::iterator it= src.find(i);
		if(it!=src.end())
		   src.erase(it );
		}    
		//src.erase(it,src.end());
	}
	return result;
}


int main(int,char**){
	std::set<int> vec;
	int max_2(MAX-MAX/2-MAX/3-MAX/5+MAX/6+MAX/10+MAX/15-MAX/30+3);
	//	vec.reserve(max_2);
	for(int i(3);i<=MAX;i+=2){
		if(i!=3 && i%3==0) continue;
		if(i!=5 && i%5==0) continue;
		vec.insert(i);
	}
	std::vector<int> primes;
	primes.reserve(10000);
	primes =Eratosthenes(vec);
	int n;
	while(std::cin >>n){
		std::vector<int>::const_iterator const it= std::upper_bound(primes.begin(),primes.end(),n);
		int off=it -primes.begin();
		if(n>=2){ ++off; }
		std::cout << off <<std::endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>
#define MAX_N 1000000

int main(){
    bool p[MAX_N+1];    // p[NUM] : NUM is Prime?
    int n;

    for(int i = 0; i <= MAX_N; i++) p[i] = true;

    for(int i = 1; i <= MAX_N; i++){
        if(i == 1) p[i] = false;
        else{
            if(p[i]){
                for(int j = 2; i * j <= MAX_N; j++){
                   p[i*j] = false;
                }
            }
        }
    }
 
    // for(int i = 0; i <= MAX_N; i++) if(p[i]) printf("%d\n",i);
    
    while(scanf("%d", &n)){
        int count = 0;
        for(int i = 1; i <= n; i++){
            if(p[i])count++;
        }
        printf("%d\n", count);
    }
    return 0;
}