Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

const (
	MAX  = 1000000
	SQRT = 1000
)

func main() {
	comp := make([]int, MAX+2)
	sieve := func() {
		for i := 3; i < SQRT; i += 2 {
			if comp[i] == 0 {
				for j := i * i; j < MAX; j += i {
					comp[j] = 1
				}
			}
		}
	}
	sieve()
	tbl := make([]int, MAX+2)
	tbl[2] = 1
	k := 1
	for i := 3; i < MAX; i += 2 {
		if comp[i] == 0 {
			k++
		}
		tbl[i+1], tbl[i] = k, k
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		ans := 0
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			p, _ := strconv.Atoi(buf[0])
			m, _ := strconv.Atoi(buf[1])
			a, b := p-m, p+m
			if a < 2 {
				a = 2
			}
			if b > MAX {
				b = MAX
			}
			ans += tbl[b] - tbl[a-1] - 1
		}
		if ans < 0 {
			ans = 0
		}
		fmt.Println(ans)
	}
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

bool prime[1000001]; //10^6
int t[1000001*2];

//素数列挙
void init_prime()
{
	memset(prime,1,sizeof(prime));
	prime[0] = prime[1] = false;
	for(int i = 2; i < sizeof(prime); i++) if(prime[i])
		for(int j = i * 2; j < sizeof(prime); j += i) prime[j] = false;
	t[0] = 0;
	for(int i = 0; i < sizeof(prime); i++) t[i+1] = t[i] + prime[i];
	for(int i = sizeof(prime); i < sizeof(t)/sizeof(int); i++) t[i+1] = t[i];
}

int main(){
	init_prime();
	int n;
	while(cin>>n,n){
		int p = 0;
		FOR(i,n){
			int x,y; cin>>x>>y;
			if(y == 0) p -= 1;
			else {
				int cnt = t[x+y]-t[max(x-y-1,0)];
				p += cnt-1;
			}
		}
		cout << p << endl;
	}

	return 0;
}

C++: #include<iostream>
#include <algorithm>
#include<functional>//greaterの使用
using namespace std;
#define MAX_LIST 999983+100
#define MP 999983

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	for(int i=MP+1;i<MAX_LIST;i++){
		prime[i]=0;
	}
	
	int prime_num[MAX_LIST];
	prime_num[0]=1;
	for(int i=1;i<MP;i++){
		prime_num[i]=prime_num[i-1]+prime[i];
	}
	
	
	int pair_num;
	while(cin>>pair_num,pair_num){
		int ans=0;
		for(int i=0;i<pair_num;i++){
			int p,m;
			cin>>p;
			cin>>m;
			int x=0;
			int a,b;
			if(p+m>MP){
				a=MP;
			}else{
				a=p+m;
			}
			if(p-m<0){
				b=0;
			}else{
				b=p-m;
			}
			x=prime_num[a]-prime_num[b];
			
			if(x==0){
				ans--;
			}else{
				x--;
				ans=ans+x;
			}
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

//#define MAX 10000
#define MAX		1000000
#define INDEX	100000
//素数配列
int h_sosu[INDEX] = {0};

//----- 列挙関数 -----//
void f_sosu();


int main(void)
{
	//素数を列挙
	f_sosu();

	//入力変数
	int n = 0;

	while (true)
	{
		cin >> n;
		if (n == 0)	{	return 0;	}

		//答え変数(王が1払ってくれる)
		int ans = 0;
		//当たりくじ
		int atari = 0;
		//組
		int kumi = 0;

		//入力
		for (int i = 0; i < n; i++)
		{
			cin >> atari >> kumi;
			//ループ変数
			int j = atari - kumi;
			//終了
			int end = atari + kumi;
			//1は政府が支払う
			bool flag_in = false;

			int count = 0;
			//負数はいらない
			if (j < 0)	{	j = 0;	}
			//値が大きすぎるなら
			if (end >= MAX)	{end = MAX;	}
			while (h_sosu[count] < j && h_sosu[count] != 0)
			{
				count++;
			}
			while (h_sosu[count] <= end && h_sosu[count] != 0)
			{
				count++;
				ans++;
			}
			ans--;
		}

		cout << ans << endl;
	}

	return 0;
}



//*****----- 素数列挙(エラトステネスのふるい) -----*****//

void f_sosu()
{
	//2 , 3は加えておく
	register int count = 2;
	h_sosu[0] = 2 , h_sosu[1] = 3;
	//終了の値
	register int end = 0;
	//素数flag
	register bool flag_sosu = false;

	for (int i = 5; i < MAX; i += 2)
	{
		//flag初期化
		flag_sosu = true;
		//平方根までで良い
		end = sqrt((double)i);
		//カウント変数まで回す
		for (int j = 0; j < count; j++)
		{
			if (i % h_sosu[j] == 0)
			{
				flag_sosu = false;
				break;
			}
			if (h_sosu[j] > end)	{	break;	}
		}
		//素数なら
		if (flag_sosu == true)
		{
			h_sosu[count++] = i;
		}
	}
}

C++: //include
//------------------------------------------
#include <bits/stdc++.h> // only for GCC

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

//clear memory
// ------------------------------------------
#define clr(a,i) memset((a), (i) ,sizeof(a))

int lcm(int a,int b){
   return a*b/__gcd(a,b);
}
 
vb pn(1000001,1); 
void prime_number(ull n){
   //fill(all(pn),1);
   pn[0]=false;pn[1]=false;
   loop(i,2,n/2+1){
      if(!pn[i]) continue;
      for(ull j=2;i*j<=n;j++){
         pn[i*j]=false;
      }
   }
}

int main(){
   ull n,s,g;
   ll p,m;
   int x;
   prime_number(999983);
   while(cin >> n&&n){
      x=-n;
      rep(i,n){
         cin>>p>>m;
         if(p-m<0) s=0;
         else s=p-m;
         if(p+m>999983) g=999984;
         else g=p+m+1;
         x+=count(pn.begin()+s,pn.begin()+g,1);
      }
      cout << x << endl;
   }
   return 0;
}

C++: #include<iostream>
using namespace std;
int x[2000000];

void prime(int p) {
	x[2] = 1;
	for (int i = 3; i < p; i += 2) {
		for (int j = 3; j * j <= i; j += 2) {
			if (i%j == 0) { goto E; }
		}
		x[i] = 1;
	E:;
	}
}

int n, m, c, sum;

int main() {
	prime(1000000);
	while (true) {
		sum = 0;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> m >> c;
			for (int j = m - c; j <= m + c; j++) {
				sum += x[j];
			}
			sum -= 1;
		}
		cout << sum << endl;
	}
}