LoginSignup
0
0

More than 1 year has passed since last update.

【Project Euler】Problem 40: チャンパーノウン定数

Posted at
  • 本記事はProjectEulerの「100番以下の問題の説明は記載可能」という規定に基づいて回答のヒントが書かれていますので、自分である程度考えてみてから読まれることをお勧めします。

問題 40. チャンパーノウン定数

原文 Problem 40: Champernowne's constant

問題の要約:以下のように小数点以下のに自然数を 1 から小さい順に並べた少数点以下n桁目の数を$d_n$としたときの$d_1 × d_{10}× d_{100} × d_{1000} × d_{10000} × d_{100000} × d_{1000000} $を求めよ

0.12345678910112131415161718192021... \\ 

チャンパーノウン定数(Wikipedia) に詳しい説明があります。プログラム的にはかなりシンプルです。

import numpy as np
def Cham(maxlen):  # generate Champernowne's constant as long as maxlen
  ret = ""
  for n in range(1,N+1):
    ret +=  str(n)
    if len(ret)>maxlen: break
  return ret

print(f"Answer is {np.prod([int(Cham(10**6)[10**i-1]) for i in range(NP+1)])}")

(開発環境:Google Colab)

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