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-1] == a7[i-1]
  18. count = count + 1
  19. else
  20. break
  21. end
  22.  
  23. i =i + 1
  24. end
  25.  
  26. count = count*(count+1)/2
  27. j = i
  28. while ( i<=n)
  29. if a4[i-1] != a7[i-1]
  30. break
  31. end
  32. i = i + 1
  33. end
  34. count = count + j
  35. print "#{count}\n"
  36. t = t - 1
  37. end
Success #stdin #stdout 0s 4760KB
stdin
3
3
10
100
stdout
10
10
10