Skip to content

Instantly share code, notes, and snippets.

@koki-h
Created September 23, 2015 08:57
Show Gist options
  • Select an option

  • Save koki-h/d4d0c723017f2c3ec3a1 to your computer and use it in GitHub Desktop.

Select an option

Save koki-h/d4d0c723017f2c3ec3a1 to your computer and use it in GitHub Desktop.
#AtCoder Beginner Contest 029 D問題の回答
#http://abc029.contest.atcoder.jp/tasks/abc029_d
#問題文
#高橋君は 1 以上 N 以下のすべての整数を十進表記で一回ずつ紙に書きました。
#この作業で、高橋君は 1 という数字を何個書いたでしょうか。
#時間がかかるのはわかっているので最初から部分点狙い。
max = gets
count = 0
1.upto(max.to_i) do |i|
count += i.to_s.count("1")
end
puts count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment