fork download
  1. list4 = [4, 44, 444, 4444, 44444]
  2. list7 = [7, 77, 777, 7777, 77777]
  3. list10 = [10, 100, 1000, 10000, 100000]
  4. index = -1
  5.  
  6. def equals(x, y):
  7. for i in range(index, -1, -1):
  8. mod1 = x % list10[i]
  9. mod2 = y % list10[i]
  10. if ((mod1 > list4[i]) and (mod1 <= list7[i])):
  11. group1 = 2
  12. else:
  13. group1 = 1
  14. if ((mod2 >= list4[i]) and (mod2 < list7[i])):
  15. group2 = 1
  16. else:
  17. group2 = 2
  18. if (group1 == group2):
  19. return False
  20. return True
  21.  
  22. t = int(input(''))
  23. for i in range(t):
  24. n = int(input(''))
  25. result = 0
  26. index = 0
  27. for j in range(1, n+1):
  28. if (j == list4[index + 1]):
  29. index += 1
  30. for k in range(j, n+1):
  31. if equals(j, k):
  32. result += 1
  33. print(result)
Success #stdin #stdout 0.04s 5868KB
stdin
3
3
10
100
stdout
6
31
2449