主页
题目
状态
排名
OI排名
统计
题解
请登录
常用链接
AOJ考试平台
老赵的Gitee代码
编译原理模拟考试平台
Java技术手册
FCC网站
菜鸟网
在线工具箱
字节豆包GPT
代码可视化
力扣网
牛客网
洛谷
杭电OJ
CodeForce
隐藏编译器
Problem E: Fibonacci数列(二)
上一题
正确率: $79.11\%$
下一题
Time Limit
$1$ 秒/Second(s)
Memory Limit
$512$ 兆字节/Megabyte(s)
提交总数
$1398$
正确数量
$1106$
"
裁判形式
标准裁判/Standard Judge
我的状态
尚未尝试
难度
分类标签
二分
矩阵快速幂
数论
×
为本题添加算法分类(请不要超过5个)
当前分类(单击移除):
二分
矩阵快速幂
数论
单击选择分类:
Description
描述 <p> In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: </p> <p align="center"> 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … </p> <p> An alternative formula for the Fibonacci sequence is </p> <p align="center"> <img src="/upload/image/20231126/20231126230615_83335.png" alt="" />. </p> <p> Given an integer n, your goal is to compute the last 4 digits of Fn. </p> <p class="pst"> <br /> </p>
Input
The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.
Output
For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).
Sample Input
复制
0 9 1000000000 -1
Sample Output
复制
0 34 6875
提示
<p class="pst"> As a reminder, matrix multiplication is associative, and the product of two 2 × 2 matrices is given by </p> <div class="ptx"> <p align="center"> <img src="/upload/image/20231126/20231126230700_61003.png" align="middle" />. </p> <p> Also, note that raising any 2 × 2 matrix to the 0th power gives the identity matrix: </p> <p align="center"> <img src="/upload/image/20231126/20231126230739_58852.gif" align="middle" />. </p> </div>
AOJ
Please Login