Project Euler [Problem 40]
間が空いた
記念すべき?40到達。
問題
Champernowne's constant
An irrational decimal fraction is created by concatenating the positive integers:
0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.
If represents the nth digit of the fractional part, find the value of the following expression.
私訳
チャンパーノウン定数
正の整数を結合した無理小数を考える :
0.123456789101112131415161718192021...
上記の通り小数第12位は 1 である。 を小数第 n 位としたとき、以下の式の値を求めよ。
解答方針
の一般的な計算方法を考える必要がある。
n から考えるのは大変なので、1桁, 2桁... のグループを考える。 先頭をゼロにしたいので k = 0 から初めて第 k グループを考えると、 第 k グループには 9 × 10k 個の整数が含まれていて、それぞれの整数が k+1 桁の幅を持つから、 グループの幅は になる。 であれば、 は第 m グループに属する。 あとは引き算して割り算すれば n が第 m グループの何番目かわかる。