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++: #include <iostream>
#include <vector>

using namespace std;

int main () {
	vector<int> furui(999984, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i < 999984; ++i) {
		if (furui[i] == 0) {
			for (int j = i; j <= 999983/i; ++j) {
				furui[i*j] = 1;
			}
		}
	}
	int n;
	int a, b, p, m;
	int counter;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		counter = 0;
		for (int i = 0; i < n; ++i) {
			cin >> p >> m;
			a = p-m;
			if (a < 2) {
				a = 3;
				++counter;
			}
			b = p+m;
			if (b > 999983) {
				b = 999983;
			}
			for (int j = a; j <= b; ++j) {
				if (j % 2 != 0 && furui[j] == 0) {
					++counter;
				}
			}
			--counter;
		}
		cout << counter << 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(;pair_num--;){
			int p,m;
			int x;
			cin>>p;
			cin>>m;
			
			if(p+m>MP){
				x=prime_num[MP]-prime_num[p-m];
			}else{
				x=prime_num[p+m]-prime_num[p-m];
			}
			x--;
			ans=ans+x;
			/*
			if(x<0){
				ans--;
			}else{
				x--;
				ans=ans+x;
			}*/
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
  int n, m, p;
  bool a[1000000];
  fill(a, a+1000000, true);
  a[0] = a[1] = false;

  for(int i = 2; i < 1000000; i++){
    if(a[i]){
      for(int j = i+i; j < 1000000; j += i){
	a[j] = false;
      }
    }
  }

  while(cin>>n && n){
    set<int> stt;
    while(n--){
      cin >> p >> m;

      for(int i = 0; i <= m && (p-i >= 0 || p+i <= 999983); i++){
	if(p-i >= 0 && a[p-i]){
	  stt.insert(p-i);	  
	}
	if(p+i <= 999983 && a[p+i]){
	  stt.insert(p+i);
	}
      }
    }

    cout << ((stt.size() > 1)? (stt.size()-1): 0) << endl;
  }
  
  return 0;
}

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

bool li[1000001];

void calpri();
int calx(int p, int m);
int money(int x);

int main(){
	int n, p[1000001], m[1000001], x[1000001], summoney = 0;
	while(1){
	cin >>n;										//IÊÌüÍ
	if(n == 0) break;								//nª0Åbreak
	for(int i = 0; i < n; i++){						//nÂÌIÊÌîñ
		cin >>p[i] >>m[i];
		x[i] = calx(p[i], m[i]);
		summoney += money(x[i]);
		}
		cout <<summoney <<endl;
	}
	
	return 0;
}

void calpri(){										//GgXelXÌâ¿Éæèboolì
	int max = 1000001, min = 2;						//iªf=true fÅÍÈ¢=false
	li[0] = false;
	li[1] = false;
	
	for(int i = 2; i <= max; i++){
		li[i] = 1;
	}
	
	for(int i = 2; i <= max; ){
		for(int j = (i + 1); j <= max; j++){
			if(j % i == 0){
				li[j] = false;
			}
		}
		do{
			i++;
		}while(!li[i]);
	}
}


int calx(int p, int m){								//zñliÌtrueÌ©çfJEg
	int nop = 0, max, min;
	max = p + m;
	min = p - m;
	for(int i = min; i <= max; ){
		if(li[i]){
			nop++;
		}
		do{
			i++;
		}while(!li[i]);
	}
	return nop;
}

int money(int x){							//ÜàvZ
	if(x == 0) return 0;
	else return(x - 1);
}

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

bool li[N];

void calpri();
int calx(int p, int m);
int money(int x);

int main(){
	calpri();
	cout <<"ok" <<endl;
	int n, p, m, x, summoney = 0;
	while(1){
	cin >>n;										//IÊÌüÍ
	if(n == 0) break;								//nª0Åbreak
	for(int i = 0; i < n; i++){						//nÂÌIÊÌîñ
		cin >>p >>m;
		x = calx(p, m);
		summoney += money(x);
		}
		cout <<summoney <<endl;
	}
	return 0;
}

void calpri(){										//GgXelXÌâ¿Éæèboolì
	int max = (N - 1), min = 2;						//iªf=true fÅÍÈ¢=false
	li[0] = false;
	li[1] = false;
	
	for(int i = 2; i <= max; i++){
		li[i] = 1;
	}
	
	for(int i = 2; (i * i) <= max; ){
		for(int j = (i + 1); j <= max; j++){
			if(j % i == 0){
				li[j] = false;
			}
			while(!li[max]){
				max--;
			}
		}
		do{
			i++;
		}while(!li[i]);
	}
}


int calx(int p, int m){								//zñliÌtrueÌ©çfJEg
	int nop = 0, max, min;
	if((p + m) > (N - 1)) max = (N - 1);
	else max = p + m;
	min = p - m;
	for(int i = min; i <= max; ){
		if(li[i]){
			nop++;
		}
		do{
			i++;
		}while(!li[i]);
	}
	return nop;
}

int money(int x){							//ÜàvZ
	if(x == 0) return 0;
	else return(x - 1);
}

C++: using namespace std;
int M=1000001;
bool P[1000001];
int main(){
	for(int i=2;i<1002;i++)if(!P[i])for(int j=i+i;j<M;j+=i)P[j]=1;
	P[0]=P[1]=1;
	int n,p,m,c,S;
	while(cin>>n,n){
		S=0;
		for(int j=0;j<n;j++){
			cin>>p>>m;
			/*c=0; for(int i=p-m>1?p-m:2;i<=p+m&&i<M;i++)if(!P[i])c++;
			S+=c>0?c-1:-1;*/
		}
		cout<<S<<endl;
	}
	return 0;
}

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

#define mx 1000001

using namespace std;

bool prm[mx];
int cnt[mx];

void mkPrm()
{
  fill(prm, prm+mx, true);
  prm[0] = prm[1] = false;

  for(int i = 2; i < mx; ++i)
    if(prm[i])
      for(int j = i+i; j < mx; j+=i) prm[j] = false;

  int t = 0;
  for(int i = 0; i < mx; ++i){
    if(prm[i]) ++t;
    cnt[i] = t;
  }

  return ;
}


int main()
{
  int n, s, p, m, c;
  mkPrm();

  while(cin>>n && n){
    s = 0;
    while(n--){
      cin >> p >> m;
      c = ((p+m >= mx)? cnt[mx-1]: cnt[p+m]);
      c -= (p-m < 1)? cnt[0] : cnt[p-m-1];
      s--;
      if(c > 0) s += c;
    }
    cout << ((s < 0)? 0 : s) << endl;
  }

  return 0;
}

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

vector<int>primes(1e7);
vector<int>sums(1e7 + 1);
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes[i] = true;
		}
	}
	flag = true;
}


int main() {
	hurui(999983);
	for (int i = 0; i < 1e7; ++i) {
		sums[i + 1] = sums[i] + primes[i + 1];
	}
	while (1) {
		int N; cin >> N;
		if (!N)break;
		long long int prize = 0;
		while (N--) {
			long long int p, m; cin >> p >> m;
			int amax = min(999983ll, p + m);
			int amin = max(0ll, p - m-1);
			const int aprize = sums[amax] - sums[amin];
			prize += aprize - 1;
		}
		cout << max(0ll,prize )<< endl;
	}
	return 0;
}