A DP problem

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
Giorgi
New poster
Posts: 48
Joined: Wed Jun 07, 2006 6:26 pm
Location: Georgia Tbilisi

A DP problem

Post by Giorgi »

I want to solve problem on the contest and I need your help.

I have number n and I want to find out how many digit 1 - s are in the numbers from 1 to n. how to solve it? n < 10^20.

for exapmle for n = 15 answer is 8

1
10
11
12
13
14
15

there are 8 one from 1 to 15. help please
thanks
sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

write out the binary of 0 to n on each row, and look for a pattern on each column.

The rightmost column is like this: 01010101...
The second rightmost column: 00110011...
next column: 00001111...
Giorgi
New poster
Posts: 48
Joined: Wed Jun 07, 2006 6:26 pm
Location: Georgia Tbilisi

Post by Giorgi »

I can't understand :(
can you or others explain it to me more clearly?
Post Reply

Return to “Algorithms”