Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

const (
	MAX  = 1000000
	SQRT = 1000
)

func main() {
	comp := make([]int, MAX+2)
	sieve := func() {
		for i := 3; i < SQRT; i += 2 {
			if comp[i] == 0 {
				for j := i * i; j < MAX; j += i {
					comp[j] = 1
				}
			}
		}
	}
	sieve()
	tbl := make([]int, MAX+2)
	tbl[2] = 1
	k := 1
	for i := 3; i < MAX; i += 2 {
		if comp[i] == 0 {
			k++
		}
		tbl[i+1], tbl[i] = k, k
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		ans := 0
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			p, _ := strconv.Atoi(buf[0])
			m, _ := strconv.Atoi(buf[1])
			a, b := p-m, p+m
			if a < 2 {
				a = 2
			}
			if b > MAX {
				b = MAX
			}
			ans += tbl[b] - tbl[a-1] - 1
		}
		if ans < 0 {
			ans = 0
		}
		fmt.Println(ans)
	}
}

C++: #include <iostream>
#include <cmath>
#define MAX 1000000
//78498
using namespace std;

bool prime[MAX+1];
int data[78499];

int count(int p, int m){
  int tmp=0;
  int d, u;
  d=p-m;
  if(d<0) d=0;
  u=p+m;
  if(u>MAX) u=MAX;
  /*for(int i=d;i<=u;i++){
    if(prime[i]) tmp++;
    }*/
  int i;
  for(i=0;;i++){
    if(data[i]==-1) break;
    if(data[i]>=d) break;
  }
  for(;;i++){
    if(data[i]==-1) break;
    if(data[i]>u) break;
    tmp++;
  }
  if(tmp==0){
    return -1;
  }else{
    return tmp-1;
  }
}

void eratos(){
  int n=MAX;
  for(int i=0;i<=n;i++) prime[i]=false;
  for(int i=3;i<=n;i+=2) prime[i]=true;
  prime[2]=true;
  int limit=(int)sqrt((double)n)+1;
  for(int i=3;i<=limit;i+=2){
    if(!prime[i]) continue;
    for(int j=i+i;j<=n;j+=i)
      prime[j]=false;
  }
}

main(){
  int n;
  eratos();
  data[0]=2;
  for(int i=3, j=1;i<=MAX;i+=2){
    if(prime[i]){
      data[j++]=i;
    }
  }
  data[78498]=-1;
  while(1){
    cin >> n;
    if(n==0) break;
    int ans=0;
    for(int i=0;i<n;i++){
      int p, m;
      cin >> p >> m;
      ans+=count(p, m);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include <algorithm>
#include<functional>//greaterの使用
using namespace std;
#define MAX_LIST 999983+100
#define MP 999983

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	for(int i=MP+1;i<MAX_LIST;i++){
		prime[i]=0;
	}
	
	int prime_num[MAX_LIST];
	prime_num[0]=1;
	for(int i=1;i<MP;i++){
		prime_num[i]=prime_num[i-1]+prime[i];
	}
	
	
	int pair_num;
	while(cin>>pair_num,pair_num){
		int ans=0;
		for(;pair_num--;){
			int p,m;
			int x;
			cin>>p;
			cin>>m;
			
			if(p+m>MP){
				x=prime_num[MP]-prime_num[p-m];
			}else{
				x=prime_num[p+m]-prime_num[p-m];
			}
			
			if(x<0){
				ans--;
			}else{
				x--;
				//ans=ans+x;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int furui[999984];

int main () {
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i < 999984; i++) {
		if (furui[i] == 0) {
			for (int j = i; j <= 999983/i; j++) {
				furui[i*j] = 1;
			}
		}
	}
	int n;
	int a, b, p, m;
	int counter;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		counter = 0;
		for (int i = 0; i < n; i++) {
			cin >> p >> m;
			a = p-m;
			if (a < 2) {
				a = 3;
				counter++;
			}
			b = p+m;
			if (b > 999983) {
				b = 999983;
			}
			for (int j = a; j <= b; j++) {
				if (j % 2 != 0 && furui[j] == 0) {
					counter++;
				}
			}
			counter--;
		}
		cout << counter << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int prime[10000001];

void CreatePrime()
{
	rep(i,1000001) prime[i] = 1;

	prime[0] = prime[1] = 0;

	REP(i,2,sqrt(1000001)+1)
	{
		for(int j=0;i*(j+2)<1000001;j++)
		{
			prime[i*(j+2)] = 0;
		}
	}


}

int main()
{
	CreatePrime();
	
	int n;
	while(cin >> n && n)
	{
		int ans = -n;

		rep(i,n)
		{
			int p,m;
			cin >> p >> m;

			int count = 0;
			
			int s = p-m;
			int e = p+m;

			if(s < 0) s = 0;
			if(e > 1000000) e = 1000000;
			
			REP(j,s,e+1)
			{
				if(prime[j]) count++;
			}

			if(count < 0) ans--;
			else ans += count;
		}
		
		if(ans < 0) cout << 0 << endl;
		else cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

bool prime[2000000];
int cnt[2000000];

int main(){
	fill(prime, prime + 2000000, true);
	prime[0] = prime[1] = false;
	for(int i = 2; i * i < 2000000; i++){
		if(prime[i]){
			for(int j = 2 * i; j < 2000000; j += i) prime[j] = false;
		}
	}
	int c = 0;
	rep(i, 2000000){
		if(prime[i])c++;
		cnt[i] = c;
	}

	int n, x, p, m, a, b;
	while(cin >> n && n){
		x = 0;
		rep(i, n){
			cin >> p >> m;
			x--;
			a = max(0, p - m - 1);
			b = min(999983, p + m);
			x += cnt[b] - cnt[a];
		}
		cout << x << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define MOD 1000000007
#define EPS (1e-10)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

bool is_prime[999984];
int prime[100000];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	int c = 0;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999983; i++) {
		if (is_prime[i]) {
			prime[c++] = i;
			for (int j = i * 2; j <= 999983; j += i)is_prime[j] = false;
		}
	}
	int n;
	while (scanf("%d", &n), n) {
		int sum = 0;
		rep(i, n) {
			int p, m; scanf("%d%d", &p, &m);
			int a = upper_bound(prime, prime + c, p + m) - prime - 1;
			int b = lower_bound(prime, prime + c, p - m) - prime - 1;
			sum += a - b - 1;
		}
		printf("%d\n", sum);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

vector<bool> used;
long long sum[1000001];

int main() {
	used.resize(1000001, false);
	used[0] = used[1] = true;
	for (int i = 2; i * i <= 1000001; i++) {
		if (!used[i]) {
			sum[i]++;;
			for (int j = i; j <= 1000001; j += i) used[j] = true;
		}
	}
	REP(i, 1000001) if (!used[i]) sum[i]++;
	
	FOR(i, 1, 1000001) sum[i] += sum[i - 1];
	
	int n;
	while (cin >> n, n) {
		long long ans = 0;
		REP(i, n) {
			int p, m;
			scanf("%d %d", &p, &m);
			
			int a = p - m < 0 ? 0 : p - m - 1;
			int b = p + m > 1000001 ? 1000000 : p + m;
			
			int cnt = sum[b] - sum[a];
			if (cnt == 0) ans--;
			else ans += cnt - 1;
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
bool a[1000000];
int main()
{
  int i,j,k,n,x,s;
  for(i=2;i<1000000;i++){
    if(!a[i]){
      for(j=2;i*j<1000000;j++){
	a[i*j] = true;
      }
    }
  }
  for(;;){
    cin >> n;
    if(n==0)break;
    s = 0;
    while(n--){
      cin >> i >> j;
      x = 0;
      for(k=i-j;k<=i+j;k++){
	if(2<=k && k<1000000 && a[k] == false) x++;
      }
      if(x != 0) s += x - 1;
      else s--;
    }
    cout << s << endl;
  }
  return 0;
}