fork download
  1. list4 = [4, 44, 444, 4444, 44444]
  2. list7 = [7, 77, 777, 7777, 77777]
  3. list10 = [10, 100, 1000, 10000, 100000]
  4. result = 0
  5. results = []
  6.  
  7. x1 = 0
  8. x2 = 0
  9. x3 = 0
  10. x4 = 0
  11. for i in range(100001):
  12. mod1 = i % 10
  13. mod2 = i % 100
  14. b1 = (mod2 >= 44) and (mod2 < 77)
  15. b2 = (mod1 >= 4) and (mod1 < 7)
  16. if (b1 and b2):
  17. result += x4
  18. x4 += 1
  19. elif (b1):
  20. result += x3
  21. x3 += 1
  22. elif (b2):
  23. result += x2
  24. x2 += 1
  25. else:
  26. result += x1
  27. x1 += 1
  28. results.append(result)
  29.  
  30. t = int(input(''))
  31. for i in range(t):
  32. n = int(input(''))
  33. print(results[n])
  34.  
Success #stdin #stdout 0.26s 5936KB
stdin
3
3
10
100
stdout
6
31
1654