uva 11582(大fib,打表找循环节)
2014-08-08 10:49
211 查看
f (0) = 0 and f (1) = 1
f (i+2) = f (i+1) + f (i) for every i ≥ 0
a b n
其实这题的主要知识,还是找循环节,打表。
卡点:2^64-1 ---> unsigned long long
f (i+2) = f (i+1) + f (i) for every i ≥ 0
Sample input
three integers a,b,n where 0 ≤ a,b < 264 (a and b will
not both be zero) and 1 ≤ n ≤ 1000.
T
a b n 3 1 1 2 2 3 1000 18446744073709551615 18446744073709551615 1000
Sample output
For each test case, output a single line containing the remainder of f (ab)upon
division by n.
1 21 250
其实这题的主要知识,还是找循环节,打表。
卡点:2^64-1 ---> unsigned long long
#include<iostream> #include<cstdio> #include<cmath> #include<vector> #define bug(a) cout<<a<<"--->\n"; using namespace std; typedef unsigned long long ULL; vector<int>f[1005]; int period[1005]; int qpow(ULL a,ULL b,int p) { int ans=1; while(b) { if(b&1) ans=int((ans*a)%p); a=(a*a)%p; b>>=1; } return ans; } void pre_fib() { for(int n=2;n<=1000;n++) { f .push_back(0);f .push_back(1); for(int i=2;;i++) { f .push_back((f [i-1]+f [i-2])%n); if(f [i-1]==0&&f [i-2]==1) { period =i-1; break; } } } } int main() { int T; pre_fib(); scanf("%d",&T); while(T--) { ULL a,b; int p; int c; scanf("%llu%llu%d",&a,&b,&p); if(a==0||p==1) printf("0\n"); else { c=qpow(a%period[p],b,period[p]); printf("%d\n",f[p][c]); } } return 0; }
相关文章推荐
- UVA 11582 Colossal Fibonacci Numbers!(循环节打表+幂取模)
- Uva 11582 Colossal Fibonacci Numbers! (循环节、幂取模、打表)
- UVa11582 巨大的斐波那契数 循环节计算+快速幂
- UVa11582 - Colossal Fibonacci Numbersl (打表找规律)
- uva 11582 快速幂 Fibonacci循环节
- Uva11582 Colossal Fibonacci Numbers! (数论、斐波那契循环节)
- Colossal Fibonacci Numbers! UVA 11582 寻找循环节
- uva11582 斐波拉切数列循环节+欧拉定理降幂
- Uva 11582(Fibonacci循环节)
- UVA - 11582 Colossal Fibonacci Numbers!循环节
- UVA 11582 Colossal Fibonacci Numbers!(打表+快速幂)
- UVA 11582 Colossal Fibonacci Numbers! 找循环节
- UVA - 11582 - Colossal Fibonacci Numbers!(快速幂+打表)
- UVA 202 - Repeating Decimals【循环小数循环节】
- UVALive 7279 Sheldon Numbers (暴力打表)
- UVa 568 Just the Facts (数论&打表&不打表)
- UVA - 10298 Power Strings (KMP求字符串循环节)
- UVA202 - Repeating Decimals(循环小数循环节)
- UVa 1225 - Digit Counting【打表】
- UVA-1482 Playing With Stones(SG函数打表找规律)