All Tracks Math Problem

Oz's new problem
Tag(s):

Combinatorics, Hard, Math

Problem
Editorial
Analytics

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
$$X$$$$M$$

SAMPLE INPUT
1
7 4
SAMPLE OUTPUT
5
Explanation

7 balls are numbered from 0 to 6 and 4 of them are removed. Possible removals are {0, 3, 5, 6}, {1, 2, 5, 6}, {2, 3, 4, 5}, {0, 1, 2, 4}, {1, 3, 4, 6}.

Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic, Kotlin

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

HackerEarth Collegiate Cup - First Elimination

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications