参考代码

cookiebus 2024-02-05 16:28:50 8 返回题目

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
int Q;
LL a, b, p[105];
LL f(LL x) {
    LL ans = 0, j;
    while (x) {
        j = 1;  // cnt[]和f[]的斐波那契数列错开了一位
        while (p[j + 2] <= x) j++;
        ans += p[j];
        x -= p[j + 1];
    }
    return ans;
}
int main() {
    p[1] = 1;
    p[2] = 1;  //此处求的是cnt的斐波那契数列。
    for (int i = 3; i <= 100; i++) p[i] = p[i - 1] + p[i - 2];
    scanf("%d", &Q);
    for (int i = 1; i <= Q; i++) {
        scanf("%lld%lld", &a, &b);
        printf("%lld\n", f(b) - f(a - 1));
    }
    return 0;
}
{{ vote && vote.total.up }}