Precision issue in python

mukesh tiwari mukeshtiwari.iiitm at gmail.com
Sat Feb 20 16:37:52 CET 2010


On Feb 20, 8:13 pm, mukesh tiwari <mukeshtiwari.ii... at gmail.com>
wrote:
> On Feb 20, 5:44 pm, Mark Dickinson <dicki... at gmail.com> wrote:
>
>
>
>
>
> > On Feb 20, 11:17 am, mukesh tiwari <mukeshtiwari.ii... at gmail.com>
> > wrote:
>
> > > Hello everyone. I think it is  related to the precision with double
> > > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for
> > > all test cases whose N>=100, its K<=15." I know precision of doubles
> > > in c is 16 digits. Could some one please help me with this precision
> > > issue.I used stirling (http://en.wikipedia.org/wiki/
> > > Stirling's_approximation) to calculate the first k digits of N.
> > > Thank you.
>
> > If I understand you correctly, you're trying to compute the first k
> > digits in the decimal expansion of N!, with bounds of k <= 15 and 100
> > <= N < 10**8.  Is that right?
>
> > Python's floats simply don't give you enough precision for this:
> > you'd need to find the fractional part of log10(N!) with >= 15 digits
> > of precision.  But the integral part needs ~ log10(log10(N!)) digits,
> > so you end up needing to compute log10(N!) with at least 15 +
> > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few
> > extra digits for safety);  so that's at least 25 digits needed for N
> > close to 10**8.
>
> > The decimal module would get you the results you need (are you allowed
> > imports?).  Or you could roll your own log implementation based on
> > integer arithmetic.
>
> > --
> > Mark
>
> Yes i am trying to first k digits of N!.I will try your method.
> Thank you

I am out of luck.I put d_2=d_1-int(d_1)+25 instead of d_2=d_1-
int(d_1)+K-1  but i am getting WA.
"The decimal module would get you the results you need (are you
allowed
imports?).  Or you could roll your own log implementation based on
integer arithmetic. "
I don't know if is possible to import this decimal module but kindly
tell me.Also a bit about log implementation
Thank you



More information about the Python-list mailing list