fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. const int mod = 1e9 + 7;
  5. const int N = 1000001;
  6. int dp[N];
  7. int binpow(int base, int exponent){
  8. int result = 1;
  9. if(exponent == 0) return result;
  10. if(exponent == 1) return base;
  11. result = binpow(base, exponent / 2);
  12. result *= result;
  13. result %= mod;
  14. if(exponent % 2) result *= base;
  15. return result % mod;
  16. }
  17. int sol(int n){
  18. return (4 * binpow(5, n - 1)) % mod;
  19. }
  20. signed main(){
  21. int t;
  22. cin >> t;
  23. dp[0] = 0;
  24. dp[1] = 5;
  25. for(int i = 2; i < N; i++) dp[i] = (sol(i) + dp[i - 1]) % mod;
  26. while(t--){
  27. int l, r;
  28. cin >> l >> r;
  29. cout << (dp[r] - dp[l - 1] + mod) % mod << '\n';
  30. }
  31. return 0;
  32. }
Runtime error #stdin #stdout 0.16s 11212KB
stdin
Standard input is empty
stdout
Standard output is empty