http://acm.hdu.edu.cn/showproblem.php?pid=3823
#include<stdio.h>
#include<vector>
using namespace std;
#define M 20000010
bool pri[M] = {0};
int ans[M],temp = 0;
vector<int>fans[152];
int abs(int n)
{
return n>0?n:-n;
}
void fun()
{
for(int i = 2;i*i<M;i++)
{
if(pri[i]==true)
continue;
for(int j = 2*i;j<M;j+=i)
{
pri[j] = true;
}
}
for(int i = 0;i<M;i++)
{
if(pri[i] == false)
{
ans[temp++] = i;
}
}
for(int i = 0;i<temp-1;i++)
{
int t = ans[i+1]-ans[i];
if(t<=150)
{
fans[t].push_back(ans[i+1]);
}
}
}
int main()
{
fun();
int n;
scanf("%d\n",&n);
int t = n;
while(n--)
{
int a,b;
scanf("%d%d",&a,&b);
int ca = abs(a-b);
int max = a>b?a:b;
bool boo = false;
for(int i = 0;i<fans[ca].size();i++)
{
if(fans[ca][i]>=max)
{
printf("Case %d: %d\n",t-n,fans[ca][i]-max);
boo=true;
break;
}
}
if(boo==false)
{
printf("Case %d: -1\n",t-n);
}
}
}