0
0

More than 3 years have passed since last update.

ABC083B - Some Sums

Posted at

問題

https://atcoder.jp/contests/abs/tasks/abc083_b
スクリーンショット 2019-11-26 14.48.59.png

1回目

回答

N,A,B = gets.chomp.split(" ").map(&:to_i)

res = 0
for num in 1..N do
  numList = num.to_s.chars.map(&:to_i)
  sum = 0
  for n in numList do
    sum += n
  end
  if sum >= A && sum <= B
    res += num
  end
end

puts res

結果

スクリーンショット 2019-11-26 14.51.25.png

2回目

回答

N,A,B = gets.chomp.split(" ").map(&:to_i)

res = 0

for num in 1..N do
  s = 0
  n = num
  while n > 0 do
    s += n % 10
    n /= 10
  end
  if s >= A && s <= B
    res += num
  end
end

puts res

結果

スクリーンショット 2019-11-26 14.51.52.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0