程序在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
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短