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. count = count*(count+1)/2
  26. print "#{count}\n"
  27. t = t - 1
  28. end
  29. puts a4
Success #stdin #stdout 0s 4760KB
stdin
3
3
10
100
stdout
6
6
6
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
1
1
1
2
1
1
1
1
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0