#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 1000004
using namespace std;

vector<int> prime;
bool isntprime[MAX+1]; 
void init()
{	
  isntprime[0] = isntprime[1] = true;
  int j;	
  for(int i=2;i<= MAX;i++)if(!isntprime[i])for(prime.push_back(i),j=2*i;j<=MAX;j+=i)isntprime[j] = true;
}

int main()
{
  init();
  int n;
  while(cin >> n,n)
    {
      int p,m;
      int ans = n/101;
      rep(i,n)
	{
	  cin >> p >> m;
	  int bottom = max(0,p-m);
	  int top = min(999983,p+m);
	  int X = upper_bound(all(prime),top) - lower_bound(all(prime),bottom);
	  if(X == 0)ans--;
	  else      ans += X-1;
	}
      cout << ans << endl;
    }
  return 0;
} 