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. index = -1
  6. results = []
  7.  
  8. def equals(x, y):
  9. for i in range(index, -1, -1):
  10. mod1 = x % list10[i]
  11. mod2 = y % list10[i]
  12. if ((mod1 > list4[i]) and (mod1 <= list7[i])):
  13. group1 = 2
  14. else:
  15. group1 = 1
  16. if ((mod2 >= list4[i]) and (mod2 < list7[i])):
  17. group2 = 1
  18. else:
  19. group2 = 2
  20. if (group1 == group2):
  21. return False
  22. return True
  23.  
  24. for i in range(1, 100001):
  25. for j in range(i+1):
  26. if equals(j, i):
  27. result += 1
  28. results.append(result)
  29.  
  30. t = int(input(''))
  31. for i in range(t):
  32. n = int(input(''))
  33. print(results[n-1])
Time limit exceeded #stdin #stdout 5s 5908KB
stdin
3
3
10
100
stdout
Standard output is empty