← Back to topics
Topic

Number of Digits fails for me on 4 test case any advice ?

D
Dgleich
Here is the code :
REMOVED*
h
harta01
One obvious bug is %ld for n( long long)

It must be %lld
D
Dgleich
well it fails again...
d
demjan0001
well here is mistake ...
rez = k*l1/l2
it has to be
rez = int( k*l1/double(l2) );
try now ...
D
Dgleich
Failing again :)
d
demjan0001
i am not sure why it doesn't work ...
when i submited with log(n) / log(10) it fails on 4th test case, but when i submited with log10(n) it passed all tests cases ...
i am not sure why, because: logc N = logk ( N ) / logk (c) ...
so log10(N) = log(N) / log(10) ...
D
Dgleich
You submitted code like this ?
REMOVED*
this doesn't work for me ...
d
demjan0001
i submited solution like this:

DELETED

you need to use long long ...
D
Dgleich
It works thanks, but I still don't understand what was wrong ? :D
g
gates
probably some precision error.
R
RobertGerbicz
At the 4-th test case n is a power of ten so for that n^k is a power of ten, meaning that the base 10 logarithm is an integer, so you can easily get an error.

In my solution I'm treat the n=10^e as a special case.
d
darkspirit
You are absolutelyright!!!
Any explanation though?