본문 바로가기

problem solving/Project Euler

Problem 40 - Finding the nth digit of the fractional part of the irrational number.

링크

An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...

It can be seen that the 12^(th) digit of the fractional part is 1.

If d_(n) represents the n^(th) digit of the fractional part, find the value of the following expression.

d_(1) × d_(10) × d_(100) × d_(1000) × d_(10000) × d_(100000) × d_(1000000


Solved by pencil

1~9 9 of 1-digits numbers, total 9 digits 
10 ~ 99 90 of 2-digits numbers, total 180 digits  9
100 ~ 999 900 of 3-digits numbers, total 2700 digits 189
1000 ~ 9999  9000 of 4-digits numbers, total 36000 digits  2889 
10000 ~ 99999 90000 of 5-digits numbers, total 450000 digits  38889 
100000 ~ 999999  900000 of 6-digits numbers, total 5400000 digits  488889 

d1 = 1
d10 = 1
d100 = 5
100 - 9 = 91th digit in 2-digits number block -> zero based index is 90
90 / 2 = 45th number in 2-digits number block = 55
90 % 2 = 0th digit in 55 = 5
d1000 = 3
1000 - 189 = 811th digit in 3-digits number block -> zero based index is 810
810 / 3 = 270th number in 3-digits number block = 370
810 % 3 = 0th digit in 370 = 3
and so on...