原题链接
也是一道递推题 递推公式为 a[i] = a[i-1] + a[i-2]
但是a[1] =1,a[2] = 2;很像斐波那契数列。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <vector> #include <queue> #include <algorithm> long long a[60]; void make() { int i; a[1]=1; a[2]=2; for (i=3; i<=50; i++) { a[i] = a[i-1] + a[i-2]; } } using namespace std; int main() { int cases, a1, b1; make(); cin>>cases; while (cases--) { cin>>a1>>b1; cout<<a[b1-a1]<<endl; } return 0; }