← Back to topics
Topic

my task

N
Nikola94
@admin
can you please make my task public before 2054 ? thx in advance
a
adminModerator
what is the name of the task?
a
adminModerator
Oh, i see, it is the number of digits.

I made it public. However, I must agree that the task i really, really easy.

My solution has three lines of code.

Sorry, I forgot that this wasn't the moderator forum :(
D
DuXSerbia
OMFG

It's the one of the task that we wanted to add on our competition :(
N
Nikola94
@duxassassin
sorry to disappoint you, i knew this formula long time ago, but i didn't know how to express decimal log with ln until 2 months ago... then i decided to upload it :)
p
picsel
admin owned Nikola94 xD
N
Nikola94
i knew how to calculate the number, by using log(10), but i didn't know that lg a = ln a / ln 10...
d
demjan0001
i have to say that i hate tasks like this one ...
so there aren't any idea to solve it ...
it's just question: do you know formula ? ...
and that is stupid for me, but that is just my opinion ...
a
adminModerator
Sorry, I forgot that this wasn't the moderator forum :(
a
adminModerator
I agree that this task is more like a Math problem than algorithm problem.

Sorry again for posting the solution, I thought this topic was in the moderator sub-forum (not visible to everyone).

Anyway, there are different ways to solve this problem, so its not that bad for algorithm problem as well.
d
demjan0001
can you say how to solve this task in time without that formula ???

i know that formula, but can someone explain why that formula works ???
a
adminModerator
Here is why:

You want to solve the following inequality:
10^{k} \le a^b < 10^{k+1}

The easy way to understand this is to look at the equality

\ln(x^y) = y \ln(x)

Now back to the original inequality. Since logarithm is a monotonic function, always increases. And since a^b is always bigger than zero, we can write:

\ln(10^{k})} \le \ln(a^b) < \ln(10^{k+1})
k \ln(10)} \le b \ln(a) < (k+1) \ln(10)

So we get that

k \le \frac {b \ln(a)}{\ln(10)} < (k+1)

So we get that

k = \bigg \lfloor \frac {b \ln(a)}{\ln(10)} \bigg \rfloor

And the number of digits is k+1
d
demjan0001
ok, i understand ...
or easier to explain ...
a = 10^log10(a)
so a^b = (10^log10(a))^b = 10^(log10(a)*b)
so it's int(log10(a)*b)+1 ...
and if you know log10 N = log2(N)/log2(10) ...

do you know to solve that task if you don't use that formula ???
you said: "Anyway, there are different ways to solve this problem, so its not that bad for algorithm problem as well."
a
adminModerator
Here is one example:

write A as x * 10^y. with 0.1>=x>1. Now you want to find

x^b * 10^(by)

and think how can you calculate x^b accurately enough!