Colossal Fibonacci numbers!
TheI'Th Maid numberF (I)Is recursively defined in the following way:
- F (0) = 0AndF (1) = 1
- F (I + 2) = f (I + 1) + f (I)For everyI ≥ 0
Your task is to compute some values of this sequence.
Input begins with an integerT≤ 10,000, the number of test cases. Each test case consists of three IntegersA, B, nWhere 0 ≤A, B<1, 264 (AAndBWill not both be zero) and 1 ≤N≤ 1000.
For each test case, output a single linecontaining the remainderF (AB)Upon divisionN.
Sample Input
31 1 22 3 100018446744073709551615 18446744073709551615 1000
Sample output
121250
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <limits. h ># include <vector> using namespace STD; typedef unsigned long ull; // long hanging ull n, m, MOD; vector <int> F [1001]; void Init () {for (INT I = 2; I <= 1000; I ++) {int mod = I; int A = 0, B = 1, C = (a + B) % MOD; F [I]. push_back (a); F [I]. push_back (B); F [I]. push_back (c); While (! (B = 0 & C = 1) {A = B; B = C; C = (a % mod + B % mod) % MOD; f [I]. push_back (c);} f [I]. pop_back (); F [I]. pop_back () ;}} ull quick_mod (ull A, ull B, ull m) // fast power-down range {ull ans = 1; while (B) {If (B & 1) {ans = (ANS % m) * (a % m) % m; B --;} B/= 2; A = (a % m) * (a % m) % m;} return ans;} int main () {int t; CIN> T; Init (); // while (t --) {CIN> N> m> MOD; If (mod = 1) {cout <0 <Endl; continue ;} ull Mm = f [mod]. size (); ull ans = quick_mod (n, m, mm); cout <F [mod] [ANS] <Endl;} return 0 ;}