程序在C ++中查找第N个斐波那契数的最后两位
为此,我们将提供一个号码。我们的任务是在特定位置计算并打印斐波那契数的最后两位。
示例
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void precomput(ll f[]){
//基本案例
f[0] = 0;
f[1] = 1;
for (ll i = 2; i < 300; i++) f[i] = (f[i-1] + f[i-2])%100;
}
//返回最后两位数字
int findLastDigit(ll f[], int n){
return f[n%300];
}
int main (){
ll f[300] = {0};
precomput(f);
ll n = 1;
cout << findLastDigit(f, n) << endl;
n = 61;
cout << findLastDigit(f, n) << endl;
n = 7;
cout << findLastDigit(f, n) << endl;
n = 67;
cout << findLastDigit(f, n) << endl;
return 0;
}输出结果
1 61 13 53
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便