fork(1) download
  1. class PalindromeAndPrefixSumEncapsulated:
  2. def __init__(self, n):
  3. self.n = n
  4. self.i = 0
  5. self.palindromes = [0]*n
  6. self.prefixSums = [0]*n
  7.  
  8. def add(self, val):
  9. self.palindromes[self.i] = val
  10. self.prefixSums[self.i] = val
  11. if self.i != 0:
  12. self.prefixSums[self.i] += self.prefixSums[self.i-1]
  13. self.i = self.i+1
  14.  
  15. def isFull(self):
  16. return self.i == self.n
  17.  
  18. def getPrefixSumInRange(self, L, R):
  19. return self.prefixSums[R]-self.prefixSums[L]
  20.  
  21. def getFirstPalin(self, index):
  22. return self.palindromes[index]
  23.  
  24.  
  25. def createOddPalin(inp):
  26. n = inp
  27. palin = inp
  28. n = n//10
  29. while n > 0:
  30. palin = palin*10+(n%10)
  31. n = n//10
  32. return palin;
  33.  
  34.  
  35. def generatePalindromes(palindromeAndPrefixSumEncapsulated):
  36. i = 1
  37. while not palindromeAndPrefixSumEncapsulated.isFull():
  38. palindromeAndPrefixSumEncapsulated.add(createOddPalin(i))
  39. i = i+1
  40.  
  41.  
  42. def solve(L, R, palindromeAndPrefixSumEncapsulated):
  43. power = palindromeAndPrefixSumEncapsulated.getPrefixSumInRange(L-1, R-1);
  44. base = palindromeAndPrefixSumEncapsulated.getFirstPalin(L-1);
  45. return pow(base, power, 1000000007);
  46.  
  47. palindromeAndPrefixSumEncapsulated = PalindromeAndPrefixSumEncapsulated(100001)
  48. generatePalindromes(palindromeAndPrefixSumEncapsulated)
  49. q = int(input())
  50. while q > 0:
  51. q = q-1
  52. line = input().split(" ")
  53. L, R = int(line[0]), int(line[1])
  54. print(solve(L, R, palindromeAndPrefixSumEncapsulated))
Runtime error #stdin #stdout #stderr 0.06s 67276KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 49, in <module>
    q = int(input())
EOFError