Oz's new problem
Practice
3.8 (49 votes)
Ready
Combinatorics
Hard
Approved
Mathematics
Problem
2% Success 96 Attempts 50 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Today Oz has an interesting problem for you. Oz has a set of M balls numbered from 0 to M-1. He has removed X balls from the set and calculated the sum of the numbers of removed balls. He has given you a hint that the sum is divisible by M.
Now your task is to count the number of ways of removing X balls. Output the answer modulo 109+7.

Input:
First line contains one integer T - number of test cases.
Each test case contains two space separated integers M and X.

Output:
For each test case output the desired answer modulo 109+7.

Constraints:
1 ≤ T ≤ 10
1 ≤ M ≤ 109
1 ≤ X ≤ 105
XM

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
No similar problems found