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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30
#define MAX_P 1000000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;


int p[MAX_P], n;

int main(){
  p[0] = p[1] = 1;
  REP(i, 2, MAX_P/2){
    if(!p[i]){
      for(int j = i+i; j < MAX_P; j += i) p[j] = 1;
    }
  }
  //  rep(i, 100) if(!p[i])printf("%d ", i); puts("");

  while(scanf("%d", &n) && n){
    int ip, m, res = 0;
    rep(i, n){
      scanf("%d%d", &ip, &m);
      int c = 0;
      REP(j, ip-m, ip+m+1) if(j > 0 && j < MAX_P && !p[j]) c++;
      if(c) res += c-1;
      else res--;
    }
    printf("%d\n", res);
  }
  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++;
			}
			if (a % 2 == 0) {
				a++;
			}
			b = p+m;
			if (b > 999983) {
				b = 999983;
			}
			for (int j = a; j <= b; j+= 2) {
				if (furui[j] == 0) {
					counter++;
				}
			}
			counter--;
		}
		cout << counter << 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 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 n, x, p, m;
	while(cin >> n && n){
		x = 0;
		rep(i, n){
			cin >> p >> m;
			x--;
			rep2(j, p - m, p + m + 1){
				if(0 <= j && j <= 999983 && prime[j]) x++;
			}
		}
		cout << x << endl;
	}
	return 0;
}

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

using namespace std;

const int l = 1000001;

int main()
{
	int n, s, t, c;
	bool pr[l], a[l];
	fill(pr, pr+l, true);
	pr[0] = pr[1] = false;
	
	for(int i = 2; i < l; i++){
		if(pr[i]){
			for(int j = 2*i; j < l; j+=i){
				pr[j] = false;
			}
		}
	}
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		c = 0;
		fill(a, a+l, true);
		while(n--){
			cin >> s >> t;
			for(int i = s-t; i <= s+t && i < l; i++){
				if(pr[i] && a[i]){
					c++;
					a[i] = false;
				}
			}
		}
		c--;
		if(c < 0){
			c = 0;
		}
		cout << c << 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>>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;

const int MP = 999983;
int sv[MP+1], ac[MP+1];

int main() {
	sv[0] = sv[1] = 1;
	for (int i=2; i*i<=MP; ++i) {
		if ( ! sv[i]) {
			for (int j=i*i; j<=MP; j+=i) {
				sv[j] = 1;
			}
		}
	}
	ac[0] = 0;
	for (int i=1; i<=MP; ++i) {
		ac[i] = ac[i-1] + 1 - sv[i];
	}
	int n, p, m;
	while (cin >> n, n) {
		int ret = 0, X;
		for (int i=0; i<n; ++i) {
			cin >> p >> m;
			ret += ac[min(MP, p+m)] - ac[max(0, p-m-1)] - 1;
		}
		cout << ret << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 1000000

bool li[N + 1];

void calpri();
int calx(int p, int m);
int money(int x);

int main(){
	calpri();
	cout <<"ok" <<endl;
	int n, p, m, x, summoney;
	while(1){
	cin >>n;										//IÊÌüÍ
	if(n == 0) break;
	summoney = 0;									//nª0Åbreak
	for(int i = 0; i < n; i++){						//nÂÌIÊÌîñ
		cin >>p >>m;
		x = calx(p, m);
		summoney += money(x);
		}
		cout <<summoney <<endl;
	}
	return 0;
}

void calpri(){										//GgXelXÌâ¿Éæèboolì
	int max = N, min = 2;						//iªf=true fÅÍÈ¢=false
	li[0] = false;
	li[1] = false;
	
	for(int i = 2; i <= max; i++){
		li[i] = 1;
	}
	
	for(int i = 2; (i * i) <= max; ){
		for(int j = (i + 1); j <= max; j++){
			if(j % i == 0 && li[j] != false){
				li[j] = false;
			}
			while(!li[max]){
				max--;
			}
		}
		do{
			i++;
		}while(!li[i]);
	}
}

int calx(int p, int m){								//zñliÌtrueÌ©çfJEg
	int nop = 0, max, min;
	if((p + m) > (N + 1)) max = N;
	else max = p + m;
	if(p - m < 0) min = 0;
	else min = p - m;
	for(int i = min; i <= max; ){
		if(li[i]){
			nop++;
		}
		do{
			i++;
		}while(!li[i]);
	}
	return nop;
}

int money(int x){							//ÜàvZ
	if(x == 0) return -1;
	else return(x - 1);
}