[Project Euler] Problem 40

원문: Problem 40
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 dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

비논리적인 소수를 양의 정수들을 결합하여 생성할 수 있다:

0.123456789101112131415161718192021...

소수부의 12번째 숫자는 1인 것처럼 볼 수 있다.

만약, dn을 소수부의 n번째 숫자로 표현한다면, 다음 식의 값을 찾아라.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

Python
#!/usr/bin/env python3

s = ""
for num in range(200000):
    s += str(num)

mul = 1
for k in [1, 10, 100, 1000, 10000, 100000, 1000000]:
    mul *= int(s[k])

print(mul)
접기

댓글 없음:

댓글 쓰기

크리에이티브 커먼즈 라이선스