LoginSignup
2
1

More than 5 years have passed since last update.

Project Euler 40「チャンパーノウン定数」

Posted at

素直に愚直に文字連結。
numpyを覚えたいので今後はちょくちょく使っていこうと思う。
ナムパイ?ナンパイ?ナムピー?ナンピー?

Problem 40 「チャンパーノウン定数」

正の整数を順に連結して得られる以下の10進の無理数を考える:
0.123456789101112131415161718192021...
小数第12位は1である.
dnで小数第n位の数を表す. d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000 を求めよ.

import numpy as np

def hoge():
    d = ''
    n = 1
    while len(d) < 1000000:
        d += str(n)
        n += 1
    return np.prod([ int(d[10 ** m -1]) for m in range(6) ])

print(hoge())
2
1
2

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
2
1