洞察探讨小游戏SDK接入的最佳实践以及对企业跨平台开发的优势
780
2022-11-12
【矩阵快速幂】UVA 10698 G - Yet another Number Sequence
【题目链接】click here~~
【题目大意】
Let's define another number sequence, given by the following function:
f(0) = a
f(1) = b
f(n) = f(n-1) + f(n-2), n > 1
When a = 0 and b = 1, this sequence gives the Fibonacci Sequence. Changing the values ofa and b , you can get many different sequences. Given the values ofa, b, you have to find the last m digits of f(n) .
Input
The first line gives the number of test cases, which is less than 10001. Each test case consists of a single line containing the integersa b n m. The values of a and b range in[0,100], value of n ranges in [0, 1000000000] and value ofm ranges in [1, 4].
Input
The first line gives the number of test cases, which is less than 10001. Each test case consists of a single line containing the integersa b n m. The values of a and b range in[0,100], value of n ranges in [0, 1000000000] and value ofm ranges in [1, 4].
Output
For each test case, print the last m digits of f(n). However, you shouldNOT print any leading zero.
4 0 1 11 3 0 1 42 4 0 1 22 4 0 1 21 4
| 89 4296 7711 946 |
【解题思路】
类似于fibonacci数列的求法,值得注意的是题目并不是让求简单的F(n),而是求f(n)%f(m),由题目可知,
m ranges in [1, 4].于是定义一个mod数组 const int mod[5]= {0,10,100,1000,10000};每次取模即可
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~