#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int count[1000001];
int prime[80000],size;
int flg[1000001];

bool isPrime(int x){
	for(int i=0;i<size && prime[i]<=sqrt(x);i++){
		if(x % prime[i] == 0) return false;
	}
	return true;
}

void mkPrime(void){
	prime[0] = 2;
	size = flg[2] = 1;
	flg[0] = flg[1] = 0;

	for(int i=3;i<=999983;i+=2){
		if(isPrime(i)){
			flg[i] = 1;
			prime[size++] = i;
		}
	}
}

int calX(int from,int to){
	int res = 0;
	for(int i=from;i<=to;i++){
		res += flg[i];
	}
	return res;
}

int main(void){
	int n;

	mkPrime();

	while(cin>>n && n){
		memset(count,-1,sizeof(count));
		while(n--){
			int p,m;
			cin>>p>>m;
			if(count[p] == -1) count[p] = 0;
			count[p] += calX(p-m<0?0:p-m, p+m>1000000?1000000:p+m);
		}

		int ans = 0;
		for(int i=0;i<=1000000;i++){
			if(count[i] > 0) ans += count[i] - 1;
			else if(count[i] == 0) ans--;
		}

		cout<<ans<<endl;
	}

	return 0;
}