number of digits in e^x (worked fine but not accepted in Code.IT why )

#include<stdio.h>
main()
{
long long t;
long long x;
scanf("%lld",&t);
while(t–)
{
scanf("%lld",&x);
x = (x*0.4342944819) +1 ;
printf("%lld\n",x);
}
return 0;

}

what i used is : number of digits in x^y = 1+ log(x^y)
here e^x so 1 + ln(e^x)/ln(10) = 1+ x/ln(10),
1/ln(10) = 0.4342944819 .

I gauss u had to take value of ln(10) upto 15 or 20 decimal point …

i literally typed ln10 = 2.30258509299404568401799145466844 Still prblm remained the same

i mean to say 1/ln(10)=0.4342944819 in the statement x = (x*0.4342944819) +1 ;

i know what i am saying is that instead of calculating 1/log(10) and multiplying it with x i divided x with log(10) value with the significant number of digits as u see in my comment above.

The expression,

ans = x / logl(10) + 1

was used to prepare the test cases in C++.

1 Like

I had the same issue and got 6 WA :smiley:


[1] it may be because of precision of double. 


  [1]: http://www.codechef.com/viewsolution/6043856

does it matter ? this value is exactly equal to .43429…

I used double and took e as exp(1) [ built in math function ]. Can never be too sure whenever constants like these appear in problems…

i have tried “double” still got wrong answer

without “exp” it could be done if you take ln(e^x) = x in digits calculation i mentioned above

How much time it should take depends on whether or not you have access
to a calculator (even one without the exponentiation function). With a
logarithm, you can use log (base 10) to obtain

log(13^18) = 18 log 13 = 18*1.114 = 20.05

So there are twenty-one digits in the number.

Now suppose you have no calculator at all (other than your brain), and
want to achieve this result in under one minute. If you know your
squares and square roots, and the rules for logarithms and exponents,
you can estimate it as follows:

  1. We need the number log(13), to approximately two or three
    digits accuracy, since we will multiply it by 18 as in the
    formula above to obtain the number of digits in 13^18,
    which is somewhere around twenty digits or so (it must be
    more than 10^18, which has 19 digits).

      13^2 = 169, which is approximately 170.
    
      170^2 = 28900, which is around 30000,
    
      30000^2 = 9 x 10^8 = 10^9,
    

    finally we arrive at a number whose logarithm is easy
    to evaluate, namely log(10^9) = 9.

      log(13) = (1/8) log(10^9) = 9/8 = 1.125, approximately
    

    The actual value of log(13) is 1.1139, so our estimate is
    in fact good to two and almost three digits.

  2. The rest is easy: we multiply 18 by 1.125 to obtain

    18 x 9/8 = 9 x 9/4 = 81/4 = 20.25

    So we conclude that there are twenty-one digits.

Remark: the logarithm is very forgiving - it takes numbers that are
off by factors and converts those factors to offsets. So we may have
reasonable confidence in our estimate. Although the errors are hard to
track without a calculator, note that we rounded up twice (169 to 170
and 28900 to 30000), so that we may expect that the method above gave
a slight overestimate of log(13).

I was talking to a friend about this very interesting problem, and
we developed an even quicker route to the answer:

  1. We estimate 13 as approximately equal to 14.142… = sqrt(2)*10.

  2. 13^18 is approximately [sqrt(2)*10]^18
    = 2^9 * 10^18
    = 512 * 10^18 (easy without a calculator if you remember
    your powers of 2)
    = 5.12 x 10^20

which has twenty-one digits. Now, we can even estimate the error made
in step 1:

14.14/13 is approximately 1.1, so it is a 10% overestimate.

This overestimate will propagate when we raise it to the 18th power
(the next set of equations are approximations):

(1.1)^18 = 1.21^9 = 1.44^4 x 1.21
= sqrt(2)^4 * 1.21
= 4*1.21
= 5

This says that we have overestimated the final result by a factor of
5, which puts the actual value at approximately

13^18 = 1 x 10^20 (probably good to within 10% or so)

The actual value is 13^18 = 1.125 x 10^20.

COPIED FROM : http://mathforum.org/dr.math/ (i dont follow plagiarism)

it is wrong because
log(e^x)+1 = {ln(e^x) / ln(10) } +1
= {x / ln(10)} +1
so it must be log with base e and not with base 10
(i would love to be wrong Help!!)

1 Like

read this and and try to answer my doubt if possible.