#include<iostream>
#include<algorithm>
#define INF (long long)1000001
using namespace std;
int main(){
	int SOSU[INF];
	fill(SOSU,SOSU+INF,1);
	for(int i=2;i<INF;i++){
		if(SOSU[INF]==1){
			for(int j=i+i;j<INF;j+=i) SOSU[j] = 0;
		}
	}
	for(int i=2;i<INF;i++) SOSU[i] += SOSU[i-1];

	long long a,sum,b,c;
	while(cin >> a && a){
		sum = 0;
		while(a--){
			cin >> b >> c;
			sum += p[min(b+c,INF-1)]-p[max(0,b-c-1)]+1;
		}
		cout << sum << endl;
	}
}