Pablo & Safe Houses
Practice
5 (1 votes)
Modular exponentiation
Medium
Math
Problem
18% Success 374 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Pablo has N safe houses. Each safe house is located in a different city & these cities are numbered from 1 to N. Each city is connected to every other city & any city can be reached from every other city in a single day.

Safe house located in city 1 is Pablo's favorite due to it's maximum security, so, initially Pablo will be at this safe house. Agent Murphy of DEA wants to catch Pablo & Pablo somehow gets the information that Agent Murphy knows that he is in Safe House of city 1.



So, Pablo decided to move to other safe houses & he will change his safe house every day for the next K days. But he is not sure in which order he should move to different safe houses. So, your task is to help Pablo by determining the number of ways in which he can end up at safe house of city 1 by changing safe house every day for the next K days.

INPUT :

  • First line contains an integer T denoting the number of test case(s).
  • Next T lines consists of two space separated integers representing N & K respectively.

OUTPUT :

  • For each test case print answer modulo 1000000007 (10^9 + 7) in a separate line.

CONSTRAINTS

  • 1 ≤ T ≤ 105
  • 1 ≤ N ≤ 109
  • 1 ≤ K ≤ 1018

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
Points:30
Tags:
Binary SearchModular exponentiationSieveMedium
Points:30
38 votes
Tags:
Modular ExponentiationMediumMatrix ExponentiationNumber TheoryMathematics
Points:30
Tags:
Medium