和超级楼梯用的方法类似,但是此处数组的类型需要long long型而不是int或long型,int和long都会溢出(longlong的输出写法是%lld,long是%ld,int是%d);
- #include
- #include
-
- void main()
- {
- int n, i, a, b,len,j;
- long long* arr;
- while (~scanf_s("%d", &n))
- {
- for (i = 0; i < n; i++)
- {
- scanf_s("%d%d", &a, &b);
- len = b - a + 1;
- arr = (long long*)malloc(len * sizeof(long long));
- for (j = 0; j < len; j++)
- {
- if (j < 3)arr[j] = j;
- else arr[j] = arr[j - 1] + arr[j - 2];
- }
- printf("%lld\n", arr[j - 1]);
- }
- }
- }