题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1715
题目大意:求第N个菲波数 f(x) = f(x - 1) + f(x - 2).
解题思路:因为要求到第1000个,所以非常数值非常大,得用高精度做。题目已经确定1000个了,可以打表,以防超时。
模板连接:http://blog.csdn.net/keshuai19940722/article/details/10087993
int main() {
int n, cas;
bign num[1005];
cin >> cas;
num[1] = num[2] = 1;
for (int i = 3; i <= 1000; i++)
num[i] = num[i - 1] + num[i - 2];
while (cas--) {
cin >> n;
num[n].put();
cout << endl;
}
return 0;
}

本文介绍了一种使用高精度算法求解斐波那契数列的方法,适用于求解较大的斐波那契数,如第1000个数。通过预计算并存储斐波那契数列的方式避免了重复计算,有效防止了时间超限。
&spm=1001.2101.3001.5002&articleId=10096429&d=1&t=3&u=810fefa852c5413891bcbd1760d4e660)
1022

被折叠的 条评论
为什么被折叠?



