24h購物| | PChome| 登入
2012-06-18 13:43:10| 人氣871| 回應0 | 上一篇 | 下一篇

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

推薦 0 收藏 0 轉貼0 訂閱站台

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.

台長: Morris
人氣(871) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][DP, JAVA] 11375 - Matches
此分類上一篇:[UVA][費式延伸 矩陣 D&C] 10689 - Yet another Number Sequence

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文