fork download
  1. t = Integer(gets)
  2. while t > 0
  3. a4 = []
  4. a7 = []
  5. n = Integer(gets)
  6. i = 1
  7.  
  8. while i <= n
  9. a4 << i.to_s.count("4")
  10. a7 << i.to_s.count("7")
  11.  
  12. i = i + 1
  13. end
  14. count = 0
  15. i = 1
  16. while (a4[i] == a7[i] && i<=n)
  17. i =i + 1
  18. end
  19. count = i*(i-1)/2
  20. print "#{count}\n"
  21. t = t - 1
  22. end
Success #stdin #stdout 0s 4760KB
stdin
3
3
10
100
stdout
6
3
3