#include <iostream>
#include <algorithm>
using namespace std;

const int PRIME_SIZE = 1000000;

int main()
{
	bool prime[ PRIME_SIZE ] = { 0 };
	prime[ 0 ] = prime[ 1 ] = true;
	for( int i = 2; i < PRIME_SIZE; ++i ){
		if( prime[ i ] ) continue;
		for( int j = i + i; j < PRIME_SIZE; j += i ){
			prime[ j ] = true;
		}
	}

	int n;
	while( cin >> n && n ){
		int pay = -n;
		int* hit = new int[ PRIME_SIZE ]();
		for( int i = 0; i < n; ++i ){
			int p, m;
			cin >> p >> m;
			int low = max( 0, p - m );
			int high = min( PRIME_SIZE - 1, p + m );
			int count = 0;
			for( int j = low; j <= high; ++j ){
				++hit[ j ];
			}
		}
		for( int i = 0; i < PRIME_SIZE; ++i ){
			if( !prime[ i ] ) pay += hit[ i ];
		}

		cout << ( pay < 0 ? 0 : pay ) << endl;

		delete[] hit;
	}
	return 0;
}