#P16581. [GKS 2016 #B] Sherlock and Watson Gym Secrets

    ID: 16554 Type: RemoteJudge 6000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>数学2016数论容斥原理Google Kick Start

[GKS 2016 #B] Sherlock and Watson Gym Secrets

题目描述

Watson and Sherlock are gym buddies.

Their gym trainer has given them three numbers, AA, BB, and NN, and has asked Watson and Sherlock to pick two different positive integers ii and jj, where ii and jj are both less than or equal to NN. Watson is expected to eat exactly iAi^A sprouts every day, and Sherlock is expected to eat exactly jBj^B 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 KK, then they get along well that day.

So, Watson and Sherlock need your help to determine how many such pairs of (i,j)(i, j) exist, where iji \neq j. As the number of pairs can be really high, please output it modulo 109+710^9+7 (10000000071000000007).

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of one line with 44 integers AA, BB, NN and KK, as described above.

输出格式

For each test case, output one line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy 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 11, the possible pairs are (1,2)(1, 2), (1,5)(1, 5), (2,1)(2, 1), (2,4)(2, 4), (4,2)(4, 2), (4,5)(4, 5), (5,1)(5, 1), and (5,4)(5, 4). In Case 22, the possible pairs are (1,2)(1, 2), (1,3)(1, 3), and (4,1)(4, 1). In Case 33, No possible pairs are there, as iji \neq j.

Limits

1T1001 \le T \le 100.

0A1060 \le A \le 10^6.

0B1060 \le B \le 10^6.

Small dataset (Test set 1 - Visible)

1K100001 \le K \le 10000.

1N10001 \le N \le 1000.

Large dataset (Test set 2 - Hidden)

1K1000001 \le K \le 100000.

1N10181 \le N \le 10^{18}.