SEQAGAIN - Easy Sequence!
Your task is to find the nth term of the following sequence :
F(n) = [F(n-1)*F(n-2)]K for n>1
F(0), F(1), n and K will be provided as input. Modulus for all calculations is 1000000007. You should print the answer modulo 1000000007 i.e. F(n)%1000000007
Input
Input starts with a line containing an integer T ≤ 5000 which is the number of test cases in the file. Your program will be run on several input files.
Each test case consists of four space separated integers : F(0), F(1), n and K.
Output
T lines containing one integer each, corresponding to the answers for the T test cases.
Constraints
0 ≤ n ≤ 1018
0 ≤ K ≤ 109
0 ≤ F(0), F(1) ≤ 106
Example
Input: 1 1 1 2 1
Output: 1
hide comments
darryl:
2014-06-05 03:04:03
The following problem is quite similar
|
|
Nipun Poddar:
2014-06-05 03:04:03
would u plz check my submission, id-8685934..& tell me why its giving WA |
|
npsabari:
2014-06-05 03:04:03
Remember n can 0 also, in which case you have to print the given number! This gave 5 WA! |
|
Mostafa 36a2:
2014-06-05 03:04:03
RE: thanks :D
|
|
devu:
2014-06-05 03:04:03
@Himanshu Sachdeva:Thanks a lot for answering my query.
|
|
devu:
2014-06-05 03:04:03
@Himanshu Sachdeva : Could you please check my submission id 7222941 and tell me y i am getting wa!!
|
|
:D:
2014-06-05 03:04:03
http://en.wikipedia.org/wiki/Modular_arithmetic |
|
Mostafa 36a2:
2014-06-05 03:04:03
"Modulus for all calculations is 1000000007."
|
|
[Rampage] Blue.Mary:
2014-06-05 03:04:03
It seems that discrete logarithm will lead to TLE.
|
|
Alex Anderson:
2014-06-05 03:04:03
Do you take 0^0 as 1 or as 0? Or are there no test cases like that?
|
Added by: | zingoba |
Date: | 2012-06-26 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |