Fibonacci Sums
C++
code posted
by
Mystical
created at 28 Sep 22:40
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <iostream> #include <cstdlib> #include <cstdio> #define MAXN 100000 #define MOD 10009 using namespace std; int main() { int t, x, y, fib[MAXN+1]; scanf ("%d", &t); while (t--) { int r=0; bool done=false; scanf ("%d %d", &x, &y); fib[0]=0; fib[1]=1; if (!done) { for (int k=2; k<=MAXN; k++) { fib[k]=fib[k-1]+fib[k-2]; } done=true; } for (int j=x; j<=y; j++) { r += fib[j]; } printf("%d\n", r%MOD); } return 0; } |
615 Bytes in 2 ms with coderay