11029 - Leading and Trailing

All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes »

AC.... Finally :D Thx to kp,mamun,helloneo...
C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

Post by C »

kp wrote:Let C = A^B,

lg(C) = B*lg(A), lg - decimal logarithm lg(x) = ln(X)/ln(10).
First three digits of C are first three digits of mantissa of lg(C).

That's how I got AC (not sure about mathematical correctness).
kp: I really don't understand,why first three digits of C are first three digits of mantissa of lg(C)?? For example,
lg(123456)= 5.091512... where is 123 ???
or can someone else explain it to me ??
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

It's actually antilog of first 3 digits of mantissa of log(c).
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

kp wrote:Let C = A^B,

lg(C) = B*lg(A), lg - decimal logarithm lg(x) = ln(X)/ln(10).
First three digits of C are first three digits of mantissa of lg(C).

That's how I got AC (not sure about mathematical correctness).
how do u calulate mantissa in c++? :oops:
If I will myself do hashing, then who will do coding !!!
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

It's not a question of C++. It's simple maths.

Of a number, say 12.589, .589 is the mantissa. So you can calculate mantissa of a vlaue, x
mantissa(x) = x - floor(x)
You can use frexp() function in C/C++.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

some doubts

Post by little joey »

I also calculated the first three digits using <math.h> and got accepted, but I still have some doubts about precision.
How can we be sure that a 100-million digit number that starts off "123999999999999999999999999..." is not printed as "124..." without doing bigint calculus?
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

ohhhh. :oops: Sorry for the silly question :wink:
If I will myself do hashing, then who will do coding !!!
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

one last question :(
How to calculate this antilog?
If I will myself do hashing, then who will do coding !!!
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

If you do log calculation in base 10 ie. log10() then use pow(10,x) for antilog and if base is e ie. log(), then use exp().
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

thanks :wink:
If I will myself do hashing, then who will do coding !!!
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

I need some help for the leading part..
what is the problem with the following code snippet :

double dd=(double)k*log(mm);
char buf1[30];
sprintf(buf1,"%.Lf",exp(dd));

I have got WA
If I will myself do hashing, then who will do coding !!!
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

I did the first three with fast exponentiation, I just kept moving the decimal point so it wouldn't go into infinity. Never occured to me that I could've used logs :)
C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm

why WR

Post by C »

Please help me,I have read all posts here, but have no idea..
My code is:

Code: Select all

AC ed..
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Re: some doubts

Post by Cho »

little joey wrote:I also calculated the first three digits using <math.h> and got accepted, but I still have some doubts about precision.
How can we be sure that a 100-million digit number that starts off "123999999999999999999999999..." is not printed as "124..." without doing bigint calculus?
I think the 4th to 15th digit can be considered as some sort of pseudo-random number, then the probability that all these digits being 9 is exponentially small.
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay »

Darko wrote:I did the first three with fast exponentiation, I just kept moving the decimal point so it wouldn't go into infinity.
For the trailing part I used the Square-and-multiply method .
How to use the same for the leading .. I really can't understand :cry:
If I will myself do hashing, then who will do coding !!!
Post Reply

Return to “Volume 110 (11000-11099)”