#include <iostream>
#include <algorithm>

using namespace std;

const int amax = 1000000;

bool prime(int v)
{
	if(v == 2){
		return true;
	}
	if(v < 2 || v%2 == 0){
		return false;
	}
	
	for(int i = 3; i*i <= v; i+=2){
		if(v%i == 0){
			return false;
		}
	}
	
	return true;
}

int main()
{
	int n, s, t, c;
	bool a[amax];
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		c = 0;
		fill(a, a+amax, true);
		while(n--){
			cin >> s >> t;
			for(int i = s-t; i <= s+t && i < amax; i++){
				if(prime(i) && a[i]){
					a[i] = false;
					c++;
				}
			}
		}
		
		c--;
		if(c < 0){
			c = 0;
		}
		cout << c << endl;
	}
	
	return 0;
}