1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <vector>6#include <iostream>7#include <algorithm>8 using namespacestd;9typedef unsignedLong Longull;Ten Const intINF =1<< -; One A intT,n; -vector<int> fib[1005];///The table, the two-dimensional array subscript represents the corresponding divisor, to take the remainder - intcyc[1005];///The corresponding period of the deposit divisor p the ull A, b; - - voidpre_process () { - for(intp =2; P <= +; ++p) {///p = N (that is, divisor) +Fib[p].push_back (0); -Fib[p].push_back (1); + for(inti =2; ; ++i) { AFib[p].push_back (Fib[p][i-1] + fib[p][i-2]) %p);///The remainder is stored in the "one array" corresponding to P at if(Fib[p][i] = =1&& Fib[p][i-1] ==0) {///Find a cycle cycle -CYC[P] = i-1;/// record period End position - Break; - } - } - } in } - to intQuick_pow_mod (ull x,ull y,intMoD) {//Template code + intAns =1; - while(y) { the if(Y &1) ans = (int) ((ans * x)%MoD); *x = (x * x)%MoD; $Y >>=1;Panax Notoginseng } - returnans; the } + A intMain () { the pre_process ();///Play Watch +scanf"%d",&t); - while(t--){ $scanf"%llu%llu%d",&a,&b,&n); $ if(A = =0|| n = =1) printf ("0\n"); - Elseprintf"%d\n", Fib[n][quick_pow_mod (a%cyc[n],b,cyc[n]); - } the return 0; -}
UVa11582 huge Fibonacci numbers.