問題
https://atcoder.jp/contests/abc146/tasks/abc146_c
回答
A,B,X = gets.chomp.split.map(&:to_i)
result = 0
max = 1000000000
if A + B > X
elsif X >= A * max + B * ( max.to_s.length )
result = max
else
N = X.to_s.length
N.step( 1, -1 ) do |n|
p = A * ( 10 ** ( n - 1 ) ) + B * n
if p <= X
result = ( X - B * n ) / A
if result.to_s.length != n
result -= 1
end
break
end
end
end
p result
結果
感想
result = ( X - B * ( n + 1 ) ) / A
で割り切れちゃって、桁が1つ多くなってしまった場合がわからなくて一生悩んでしまった・・・