Looking for Fn = (Fn-1 + Fn-2) mod n's Loop section
Violence can be found
1#include <cstdio>2#include <iostream>3#include <cstring>4typedef unsignedLong Longll;5 using namespacestd;6 Const intMAXN =1023;7ll f[maxn][maxn*Ten];8 intCIRCLE[MAXN];9 Ten voidinit () { One for(intK =2; k<= +; k++){ Af[k][0] =0, f[k][1] =1; - for(inti =2; ; i++){ -F[k][i] = (f[k][i-1] + f[k][i-2])%K; the if(F[k][i] = =1&& f[k][i-1] ==0){ -Circle[k] = i1; - Break; - } + } - } + } A ll Quick_mod (ll A, ll B, ll MoD) { atll ans =1; - while(B >0){ - if(b&1){ -b--; -Ans = ans*a%MoD; - } inb >>=1; -A = a*a%MoD; to } + returnans; - } the voidSlove (ll A, ll B,intN) { * intres = Quick_mod (a%Circle[n], B, Circle[n]); $cout << F[n][res] <<Endl;Panax Notoginseng } - intMain () { the //freopen ("Data.in.txt", "R", stdin); + //freopen ("Data.out.txt", "w", stdout); A intt, N; the ll A, B; + init (); -scanf"%d", &t); $ while(t--) { $Cin >> a >> b >>N; - if(n = =1|| A = =0) cout<<0<<Endl;; - ElseSlove (A, B, n); the } - return 0;Wuyi}
UVA-11582 Colossal Fibonacci numbers! Cycle Festival