#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>
const int N = 1000000;
const int RATE = 9973;

int p[N];

void prime(){
  REP(i, N) p[i] = 1;
  p[0] = 0; p[1] = 0;
  for(int i = 2; i < N; ++i){
    if(!p[i]) continue;
    for(int j = i + i; j < N; j += i) p[j] = 0;
  }
  FOR(i, 1, N) p[i] += p[i - 1];
}

int main() {
  prime();
  int n;
  while(cin >>n && n){
    vector<P> v(n);
    map<int, int> m;
    REP(i, n){
      cin >>v[i].first >>v[i].second;
      m[v[i].first] += p[min(N - 1, v[i].first + v[i].second)] - p[max(0, v[i].first - v[i].second - 1)];
    }
    int ans = 0;
    for(map<int, int>::iterator it = m.begin(); it != m.end(); ++it){
      if((*it).second == 0) --ans;
      else ans += ((*it).second - 1);
    }
    cout <<max(0, ans) <<endl;
  }
  return 0;
}