1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | a4 = [] a7 = [] ans = [] def add (a4,a7,l,r) sum4 = 0 sum7 = 0 (l..r).each { |i| sum4 = sum4 + a4[i] sum7 = sum7 + a7[i] } if(sum4 == sum7) return 1 end return 0 end t = gets.to_i len = 0 (1..t).each { n = gets.to_i (len+1..n).each {|i| a4[i] = i.to_s.count('4') a7[i] = i.to_s.count('7') len = len + 1 } count = 0 (1..n).each { |l| (l..n).each{ |r| if r > ans.length count = count + add(a4,a7,l,r) else count = count + ans[r-1] end } } ans << count print "#{ans[n-1]}\n" } |
-
upload with new input
-
result: Success time: 0s memory: 4760 kB returned value: 0
1 2
-
result: Success time: 0s memory: 4760 kB returned value: 0
1 3
-
result: Success time: 0s memory: 4760 kB returned value: 0
1 4
-
result: Success time: 0s memory: 4760 kB returned value: 0
1 10
-
result: Success time: 0s memory: 4760 kB returned value: 0
3 1 2 10
1 3
-
result: Success time: 0s memory: 4760 kB returned value: 0
2 1 2
1 3



