Amakusa, the evil spiritual leader has captured the beautiful princess Nakururu. The reason behind this is he had a little problem with Hanzo Hattori, the best ninja and the love of Nakururu. After hearing the news Hanzo got extremely angry. But he is clever and smart, so, he kept himself cool and made a plan to face Amakusa.

Before reaching Amakusa's castle, Hanzo has to pass some territories. The territories are numbered as a, a+1, a+2, a+3 ... b. But not all the territories are safe for Hanzo because there can be other fighters waiting for him. Actually he is not afraid of them, but as he is facing Amakusa, he has to save his stamina as much as possible.

He calculated that the territories which are primes are safe for him. Now given a and b he needs to know how many territories are safe for him. But he is busy with other plans, so he hired you to solve this small problem!

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case contains a line containing two integers a and b (1 ≤ a ≤ b < 231, b - a ≤ 100000).

Output

For each case, print the case number and the number of safe territories.

Sample Input

3

2 36

3 73

3 11

Sample Output

Case 1: 11

Case 2: 20

Case 3: 4

Note

A number is said to be prime if it is divisible by exactly two different integers. So, first few primes are 2, 3, 5, 7, 11, 13, 17, ...

 

要求求出给定区间[a,b]内素数的个数,a,b很大,但是b-a在可接受的范围之内,使用区间素数筛。

先筛出b-a个素数,然后对于每个筛出来的素数在[a,b]中第一次出现的位置向后筛,筛完后得到素数的个数。

(先贴个板子 待会回来加注释qwq) 我没有咕!

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=1e5+10;
bool vis[N];
int pri[N];
int tot;
bool ans[N];

void init()///埃式筛/欧拉筛 预处理出[1,b-a]中的素数 [a,b]中的合数不会超过[1,b-a]中最大素数的2倍
{
    memset(vis,0,sizeof(vis));
    vis[0]=vis[1]=1;
    tot=0;
    for(int i=2;i<N;i++)
    {
        if(!vis[i])
        {
            pri[++tot]=i;
            for(int j=i+i;j<N;j+=i)
                vis[j]=1;
        }
    }
}

int solve(ll a, ll b)
{
    memset(ans,0,sizeof(ans));
    for(int i=1; i<=tot && 1ll*pri[i]*pri[i] <= b; i++)
    {
        ll s = (a+pri[i]-1) / pri[i];///找到大于a的第一个该素数的倍数(a是pri[i]的几倍 向上取整)
        if(s < 2)///至少是素数的2倍
            s = 2;
        s *= pri[i];
        for(; s <= b; s += pri[i])
            ans[s - a]=1;///b很大 数组开不下 为了防止数组越界 进行下标偏移
    }
    int res = 0;
    for(int i = 0; i <= b-a; i++)///下标偏移后 [0,b-a]即对应[a,b]
    {
        if(!ans[i])///是素数
        {
            res++;
            cout<<i<<'\n';
        }
    }
    if (a == 1)///最小的素数是2 a是1的时候没有删掉1
        res--;
    return res;
}
int main()
{
    init();
    int t,kcase=0;
    ll a,b;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld",&a,&b);
        int res=solve(a,b);
        cout<<"Case "<<++kcase<<": "<<res<<'\n';
    }
    return 0;
}