#P16581. [GKS 2016 #B] Sherlock and Watson Gym Secrets
[GKS 2016 #B] Sherlock and Watson Gym Secrets
题目描述
Watson and Sherlock are gym buddies.
Their gym trainer has given them three numbers, , , and , and has asked Watson and Sherlock to pick two different positive integers and , where and are both less than or equal to . Watson is expected to eat exactly sprouts every day, and Sherlock is expected to eat exactly sprouts every day.
Watson and Sherlock have noticed that if the total number of sprouts eaten by them on a given day is divisible by a certain integer , then they get along well that day.
So, Watson and Sherlock need your help to determine how many such pairs of exist, where . As the number of pairs can be really high, please output it modulo ().
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of one line with integers , , and , as described above.
输出格式
For each test case, output one line containing Case #: , where is the test case number (starting from ) and is the required answer.
3
1 1 5 3
1 2 4 5
1 1 2 2
Case #1: 8
Case #2: 3
Case #3: 0
提示
In Case , the possible pairs are , , , , , , , and . In Case , the possible pairs are , , and . In Case , No possible pairs are there, as .
Limits
.
.
.
Small dataset (Test set 1 - Visible)
.
.
Large dataset (Test set 2 - Hidden)
.
.