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