#include <iostream>
#include <algorithm>
using namespace std;
int n, m, p, imos[1000009]; bool prime[1000009];
int main() {
	for (int i = 2; i < 1000000; i++) prime[i] = true;
	for (int i = 2; i < 1000; i++) {
		if (!prime[i]) continue;
		for (int j = i * i; j < 1000000; j += i) prime[j] = false;
	}
	while (cin >> n, n) {
		fill(imos, imos + 1000000, 0);
		for (int i = 0; i < n; i++) {
			cin >> m >> p;
			imos[max(m - p, 0)]++;
			imos[min(m + p + 1, 1000000)]--;
		}
		int s = 0, ret = 0;
		for (int i = 0; i < 1000000; i++) {
			s += imos[i];
			if (prime[i] && s) ret++;
		}
		cout << ret - 1 << endl;
	}
}