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






analyse:
A picture tells more than a thousand words.
int b = 1 2 3 4
int c = <-9x1=9-><--90x2=180--><--900x3=2700--><--9000x4=36000--><--enz-->
0.12345678910......97..99100..........9991000..........999910000....
int o = 1 10 ^^ 190 2890 ^^^^38890
int f = (x / b + p) = ---> 97
int e = (x % b) = -------------------------------------------> 0123
int p = 1 10 100 1000 10000
Problem40 = 210 elapsed time: 0 ms. Test Passed.
Geen opmerkingen:
Een reactie posten