2012-06-18 13:43:10Morris

[UVA][模數] 12465 - The Turanga Leela Problem

Problem E. The Turanga Leela Problem

Leela
Turanga Leela, from Futurama

It’s been a few years since Bender solved his famous bending problem. Today, Turanga Leela, son of Morris and Munda and captain of the Planet Express spaceship, is playing a game with Bender and Philip J. Fry.

Everybody knows that Leela is cyclop. When Leela was still an infant, her parents gave her up to an orphanarium with a note scribbled with mysterious symbols to make an impression that Leela was an alien, so that she would have a better life than a typical mutant. But other kids used to make fun of her only eye, so Leela had a very perturbing childhood.

Bender and Philip J. Fry are making fun of Leela, because apparently she doesn’t know how to count (they say her parents didn’t know how to count either, and that’s why she has only one eye. Then they burst out in explosive laughter). She insists that she knows how to count, but secretly she needs your help.

Philip J. Fry chooses a positive integer a, and Bender chooses a positive integer b. Leela is supposed to count the number of positive integers m such that a and b leave the same remainder when divided by m. In other words, she’s supposed to find the size of the set {m >0 | a b (mod m)}.

But she’s totally clueless on how to proceed. Help her, please!

Input

The input file contains several test cases (at most 150). Each test case is described with two different integers a and b on a single line (1 a, b 109).

The last line contains two zeros and should not be processed.

Output

For each test case, output one integer on a single line  — the number of positive integers m such that a and b leave the same remainer when divided by m.

Sample input and output

standard input
standard output


2 3

2 4

5 7

4 8

100 205

33043387 255936619

0 0

1

2

2

3

8

40



Explanation of the sample cases

  • 2 and 3 only leave the same remainder when divided by 1.
  • 2 and 4 leave the same remainder when divided by 1 or 2.
  • 5 and 7 leave the same remainder when divided by 1 or 2.
  • 4 and 8 leave the same remainder when divided by 1, 2 or 4.
  • 100 and 205 leave the same remainder when divided by 1, 3, 5, 7, 15, 21, 35 or 105.
  • 33043387 and 255936619 leave the same remainder when divided by 1, 2, 3, 4, 6, 8, 12, 16, 24, 48, 569, 1138, 1707, 2276, 3414, 4552, 6828, 8161, 9104, 13656, 16322, 24483, 27312, 32644, 48966, 65288, 97932, 130576, 195864, 391728, 4643609, 9287218, 13930827, 18574436, 27861654, 37148872, 55723308, 74297744, 111446616 or 222893232.