## 11029 - Leading and Trailing

Moderator: Board moderators

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:
AC.... Finally Thx to kp,mamun,helloneo...

C
New poster
Posts: 35
Joined: Mon Apr 17, 2006 1:04 pm
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
Contact:
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:
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++?
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
Contact:
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

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:
ohhhh. Sorry for the silly question
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:
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
Contact:
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:
thanks
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:
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
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

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

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:
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
If I will myself do hashing, then who will do coding !!!