language: Ruby (ruby-1.9.2)
date: 102 days 23 hours ago
link:
visibility: public
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
45
46
a4 = []
a7 = []
ans = []
pos = -1
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|
 
puts l*r
puts ans.length
if(l*r > pos )
count = count + add(a4,a7,l,r)
else
count = count + ans[l*r]
end
ans[l*r] = count 
pos = l*r
}
}
 
 
#print "#{ans[n-1]}\n"
} 
  • upload with new input
  • result: Runtime error     time: 0s    memory: 4760 kB     signal: -1

    2
    1
    10
    1
    0
    1
    2
    2
    2
    3
    3
    4
    4
    5
    5
    6
    6
    7
    7
    8
    8
    9
    9
    10
    10
    4
    11
    6
    11
    8
    11
    10
    11
    12
    11
    14
    13
    16
    15
    18
    17
    20
    19
    9
    21
    12
    21
    15
    21
    18
    21
    21
    21
    24
    22
    27
    25
    30
    28
    16
    31
    20
    31
    24
    31
    28
    31
    32
    31
    36
    33
    40
    37
    25
    41
    
    prog.rb:37:in `+': nil can't be coerced into Fixnum (TypeError)
    	from prog.rb:37: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>'