PS:避免结果溢出,在每次计算过程中就对10007取余.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin>>n;
ll b[n+1];
b[1]=b[2]=1;
for(int i=3; i<=n; i++){
b[i]=(b[i-1]+b[i-2])%10007;
}
cout<<b[n];
return 0;
}
2024-01-09 10:58:04
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin>>n;
ll b[n+1];
b[1]=b[2]=1;
for(int i=3; i<=n; i++){
b[i]=(b[i-1]+b[i-2])%10007;
}
cout<<b[n];
return 0;
}