import std.stdio;
import std.algorithm;

const int MAX = 1000001;
bool prime[MAX];

void main(){
	int n, p, m, ans, upper, lower, x;
	// make prime table
	prime[] = true;
	prime[0] = prime[1] = false;
	foreach (i; 2..MAX) if (prime[i]) for (int j = i+i; j < MAX; j+=i) prime[j] = false;

	while (readf("%d\n", &n), n) {
		ans = 0;
		foreach (i; 0..n) {
			readf("%d %d\n", &p, &m);
			upper = min(p+m, 1000000);
			lower = max(p-m, 1);
			x = -1;
			for (int j = lower; j < upper; j++) {
				if (prime[j]) x++;
			}
			ans += max(0, x);
		}
		writeln(ans);
	}
}