I think the problem is not exactly the pow function, but the fact it uses
floating point arithmetic instead of integer. It will introduce precision
errors, the mantissa can overflow, and many other things you have to keep in
mind when working with floating point arithmetic.
You should keep to integers (or long long for 64 bits) when all arithmetic
can be done with integers, writing your own pow function for 64bit integers
is a good trick in the bag. And also try to make it able to calculate (A^b %
m) for large *b* values.
Carlos Guía


On Mon, Sep 14, 2009 at 12:49 AM, vaibhav <[email protected]>wrote:

>
> In this problem I used the  pow function (present in math.h library of
> c++).It got accepted for small test case but gave me wrong answer for
> the large test case.When I later changed the program and used the
> iterative method and calculated powers iteartively rather then using
> the inbuilt pow function the answer was correct.when I compared the
> files the difference between the answers varied from 1-20. I couldnt
> qualify only due to this error.
>
> Can someone  please through some light on this working of pow function.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to