Killjee and Magic Value

3.4

13 votes
Mathematics, Modular arithmetic, Easy-Medium
Problem

In this question, Killjee gives you three integers N, M, and K. You need to find the magic value of three numbers.

Suppose P=Mi=N fibonacci[i]i! (factorial here), where fibonacci[0]=fibonacci[1]=1 and fibonacci[i] = fibonacci[i1] + fibonacci[i2]. The magic value is maximum X. Such that KXP.

Since the answer could be very large, you only need to print the magic value %109+7.

INPUT FORMAT

First line of input contains a single integer T, number of test case. T lines follow each containing three space separated integers N,M,K.

OUTPUT FORMAT

For each test case print a single integer, magic value of 3 numbers in new line.

INPUT CONSTRAINTS

  • 1NM2106
  • 1K106
  • 1T20
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For 1st test case

fib(1)=1,fac(1)=1 fib(2)=2,fac(2)=2 fib(3)=3,fac(3)=6

so P=1+4+18

now 6*3=18 which is closest multiple of 6 to 23. So, 3 is magic value for this case.

Editor Image

?