Why should the cycle section start with 0 1?
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5#include <cstring>6#include <cstdlib>7#include <queue>8#include <vector>9#include <map>Ten#include <stack> One#include <string> A - using namespacestd; - the ConstUnsignedLong Longmaxn=1001; - -UnsignedLong LongT; -UnsignedLong Longb; +UnsignedLong LongN; -UnsignedLong Longf[maxn*MAXN]; + AUnsignedLong LongPow (unsignedLong Longa,unsignedLong Longb,unsignedLong LongN) { atUnsignedLong Longtmp=a%N; -UnsignedLong Longans=1; - while(b!=0){ - if(b&1==1){ -ans= (ans*tmp)%N; - } intmp= (tmp*tmp)%N; -B=b>>1; to } + //printf ("%d\n", ans); - returnans; the } * $ intMain () {Panax Notoginsengscanf"%llu",&T); - while(t--){ thescanf"%llu%llu%llu",&a,&b,&n); +f[0]=0%N; Af[1]=1%N; theUnsignedLong LongLen; +UnsignedLong Longnow=1; - while(1){ $f[now+1]= (f[now]+f[now-1])%N; $ if(f[now]==f[0] && f[now+1]==f[1]){ -len=Now ; - Break; the } -now++;Wuyi } the //printf ("%d\n", Len); -printf"%llu\n", F[pow (A,b,len)]); Wu } - return 0; About } $ /* - 3 - 1 1 2 - 2 3 A 18446744073709551615 18446744073709551615 + the 1 - 18446744073709551615 18446744073709551615 $ */ the /* the 1 the + the - - */View Code
UVA 11582 Colossal Fibonacci numbers!