UVA 11582 Colossal Fibonacci Numbers! 数学
来源:互联网 发布:淘宝延长收货 编辑:程序博客网 时间:2024/06/08 20:16
n比较小,最多n*n就回出现循环节....
Colossal Fibonacci Numbers!
Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu
Description
Problem F: Colossal Fibonacci Numbers!
The i'th Fibonacci number f (i) is recursively defined in the following way:
- f (0) = 0 and f (1) = 1
- f (i+2) = f (i+1) + f (i) for every i ≥ 0
Your task is to compute some values of this sequence.
Input begins with an integer t ≤ 10,000, the number of test cases. Each test case consists of three integers a,b,nwhere 0 ≤ a,b < 264 (a and b will not both be zero) and 1 ≤ n ≤ 1000.
For each test case, output a single line containing the remainder of f (ab) upon division by n.
Sample input
31 1 22 3 100018446744073709551615 18446744073709551615 1000
Sample output
121250
Zachary Friggstad
Source
Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples
Root :: Prominent Problemsetters :: Zachary Friggstad
Root :: Prominent Problemsetters :: Zachary Friggstad
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef unsigned long long int uLL;uLL d[2000200],dn;uLL A,B,M;uLL quickpow(){ uLL e=1; A=A%dn; while(B) { if(B%2) { e=(e*A)%dn; } A=(A*A)%dn; B/=(uLL)2; } return e;}int main(){ int T_T; cin>>T_T; while(T_T--) { dn=0; cin>>A>>B>>M; if(M==1) { puts("0"); continue; } uLL a=(uLL)1,b=(uLL)1; uLL la=a,lb=b; d[dn++]=a;d[dn++]=b; while(true) { a=(la+lb)%M; b=(lb+a)%M; if(d[0]==a&&d[1]==b) break; d[dn++]=a;d[dn++]=b; la=a; lb=b; } cout<<d[quickpow()-1]<<endl; } return 0;}
0 0
- UVA 11582 Colossal Fibonacci Numbers! 数学
- UVA 11582 - Colossal Fibonacci Numbers!
- UVa 11582 - Colossal Fibonacci Numbers!
- UVA - 11582 Colossal Fibonacci Numbers!
- uva 11582 Colossal Fibonacci Numbers!
- UVa 11582 Colossal Fibonacci Numbers!
- UVA - 11582 Colossal Fibonacci Numbers!
- UVA 11582 - Colossal Fibonacci Numbers!
- Uva 11582 Colossal Fibonacci Numbers!
- uva 11582Colossal Fibonacci Numbers!
- 【UVa】[11582]Colossal Fibonacci Numbers!
- UVA 11582 Colossal Fibonacci Numbers!
- UVA 11582 Colossal Fibonacci Numbers!
- UVA 11582 Colossal Fibonacci Numbers!
- UVA 11582 Colossal Fibonacci Numbers!
- UVA-11582 Colossal Fibonacci Numbers!
- Colossal Fibonacci Numbers! UVA
- Colossal Fibonacci Numbers! UVA
- 2014秋C++ 第12周项目 C++函数新特征与递归函数
- 软件工程(八)——软件编码
- Linux 有问必答:在 Linux 上如何通过命令行来更改日期和时间
- errno.h头文件内容
- 线程之间的通讯---SynchronizationContext
- UVA 11582 Colossal Fibonacci Numbers! 数学
- gets和scanf函数的区别
- LeetCode Validate Binary Search Tree
- 深度学习(Deep Learning)综述及算法简介
- java final 之 终极理解 简明扼要 通俗易懂
- HDU 2686 Matrix 3376 Matrix Again(费用流)
- 软件工程(十)——软件维护
- 运维总结
- 第十一周项目二求最大公约数