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 42 43 44 | 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(l*r > ans.length) count = count + add(a4,a7,l,r) else puts l*r puts ans.length count = count + ans[l*r] end ans[l*r] = count } } #print "#{ans[n-1]}\n" } |
YTQgPSBbXQphNyA9IFtdCmFucyA9IFtdCgpkZWYgYWRkIChhNCxhNyxsLHIpCnN1bTQgPSAwCnN1bTcgPSAwCihsLi5yKS5lYWNoIHsgfGl8CnN1bTQgPSBzdW00ICsgYTRbaV0Kc3VtNyA9IHN1bTcgKyBhN1tpXQp9CmlmKHN1bTQgPT0gc3VtNykKcmV0dXJuIDEKZW5kCnJldHVybiAwCgplbmQKdCA9IGdldHMudG9faQpsZW4gPSAwCigxLi50KS5lYWNoIHsKbiA9IGdldHMudG9faQoobGVuKzEuLm4pLmVhY2gge3xpfAphNFtpXSA9IGkudG9fcy5jb3VudCgnNCcpCmE3W2ldID0gaS50b19zLmNvdW50KCc3JykKbGVuID0gbGVuICsgMQp9Cgpjb3VudCA9IDAKKDEuLm4pLmVhY2ggeyB8bHwKKGwuLm4pLmVhY2h7IHxyfAppZihsKnIgPiBhbnMubGVuZ3RoKQpjb3VudCA9IGNvdW50ICsgYWRkKGE0LGE3LGwscikKZWxzZQpwdXRzIGwqcgpwdXRzIGFucy5sZW5ndGgKY291bnQgPSBjb3VudCArIGFuc1tsKnJdCmVuZAphbnNbbCpyXSA9IGNvdW50Cn0KfQoKCiNwcmludCAiI3thbnNbbi0xXX1cbiIKfSA=
-
upload with new input
-
result: Runtime error time: 0s memory: 4760 kB signal: -1
1 2
2 2
prog.rb:36:in `+': nil can't be coerced into Fixnum (TypeError) from prog.rb:36:in `block (3 levels) in <main>' from prog.rb:30:in `each' from prog.rb:30:in `block (2 levels) in <main>' from prog.rb:29:in `each' from prog.rb:29:in `block in <main>' from prog.rb:20:in `each' from prog.rb:20:in `<main>'
-
result: Runtime error time: 0s memory: 4760 kB signal: -1
2 1 10
1 2 2 2
prog.rb:36:in `+': nil can't be coerced into Fixnum (TypeError) from prog.rb:36:in `block (3 levels) in <main>' from prog.rb:30:in `each' from prog.rb:30:in `block (2 levels) in <main>' from prog.rb:29:in `each' from prog.rb:29:in `block in <main>' from prog.rb:20:in `each' from prog.rb:20:in `<main>'



