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 ( i<=n)
  17. if a4[i] == a7[i]
  18. count = count + 1
  19. end
  20. i =i + 1
  21. end
  22. count = count*(count-1)/2
  23. print "#{count}\n"
  24. t = t - 1
  25. end
Success #stdin #stdout 0s 4760KB
stdin
3
3
10
100
stdout
3
28
2145