题目链接:https://www.luogu.org/problemnew/show/UVA12620 OR Vjudge
输入输出样例
输入样例#1: 复制
4
1 3
4 4
5 100
1 99999
输出样例#1: 复制
4
3
5068
4933400
好吧本题可以说是一个提答题(虽然不太恰当),因为模数本题是指定的模数,所以我们直接在本地机器上跑,可以证明对于斐波拉契数列取模的话一定会有循环节,然后就发现循环节是300…,就没有然后了
AC Code:
#include<bits/stdc++.h>
#define rg register
#define maxn 100005
#define il inline
#define ll long long
using namespace std;
il int read(){rg int x = 0 , w = 1;rg char ch = getchar();while (ch < '0' || ch > '9') {if (ch == '-') w = -1;ch = getchar();}while (ch >= '0' && ch <= '9'){x = (x<<3) + (x<<1) + ch - '0';ch = getchar();}return x * w;}
int f[maxn];
int main(){
rg int t = read();
ll a , b;
ll res = 2 , ans = 0;
f[1] = f[2] = 1;
for (rg int i = 3 ; i <= 300 ; ++i){
f[i] = (f[i - 1] + f[i - 2]) % 100;
res += f[i];
}
for (rg int i = 301 ; i <= 3000 ; ++i)
f[i] = (f[i - 1] + f[i - 2]) % 100;
while (t--){
ans = 0;
scanf("%lld %lld" , &a , &b);
ll tot = (b - a) / 300;
ans += tot * res;
b -= tot * 300;
ll tota = a / 300;
a = a - 300 * tota , b = b - 300 * tota;
if (!a) a += 300 , b += 300;
for (rg int i = a ; i <= b ; ++i) ans += f[i];
printf("%lld\n" , ans);
}
return 0;
}```