问题1209--LCM and Walk

1209: LCM and Walk

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 128 MB

提交

题目描述

Jerry has just learned some number theory, and can't wait to show his ability to Tom.

Now Jerry is sitting on a grid map of infinite rows and columns. Rows are numbered 1,2,⋯ from the bottom, so are the columns. At first Jerry is standing at grid (sx,sy), and begins his journey.

To show Tom his talents in math, he uses a special way of walk. If currently Jerry is at the grid (x,y), first of all, he will find the minimum z that can be divided by both x and y, and walk exactly z steps to the up, or to the right. So the next possible grid will be (x+z,y), or (x,y+z).

After a finite number of steps (perhaps zero), he finally finishes at grid (ex,ey). However, he is too tired and he forgets the position of his starting grid!

It will be too stupid to check each grid one by one, so please tell Jerry the number of possible starting grids that can reach (ex,ey)!

输入

First line contains an integer T, which indicates the number of test cases.

Every test case contains two integers ex and ey, which is the destination grid.

⋅ 1≤T≤1000.
⋅ 1≤ex,ey≤109.

输出

For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1 and y is the number of possible starting grids.

样例输入 Copy

3
6 10
6 8
2 8

样例输出 Copy

Case #1: 1
Case #2: 2
Case #3: 3

来源/分类