Re: Last M digits of expression A^N

2010-02-06 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari wrote: > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my  A and N are too large (10^100) and M is less than > 10^5. The other approach   was  repeated squaring and taking mod of > expression. Is there any other way to do t

Re: Last M digits of expression A^N

2010-02-06 Thread Dave Angel
monkeys paw wrote: mukesh tiwari wrote: Hello everyone. I am kind of new to python so pardon me if i sound stupid. I have to find out the last M digits of expression.One thing i can do is (A**N)%M but my A and N are too large (10^100) and M is less than 10^5. The other approach was repeated

Re: Last M digits of expression A^N

2010-02-06 Thread Shashwat Anand
a nice exercise to do can be this problem : http://www.codechef.com/MARCH09/problems/A4/ , it deals with both cases, first and last k digits and can be performed within O(log n) On Sun, Feb 7, 2010 at 3:58 AM, Shashwat Anand wrote: > Yes, it can be done. Have a look at : > http://en.wikipedia.org

Re: Last M digits of expression A^N

2010-02-06 Thread Shashwat Anand
Yes, it can be done. Have a look at : http://en.wikipedia.org/wiki/Modular_exponentiation The algorithm is also mentioned in CLRS.I tried writing my own modular-exponentiation code following CLRS but observed that python pow() function is much more efficient. Have a look at this problem : https://w

Re: Last M digits of expression A^N

2010-02-06 Thread monkeys paw
mukesh tiwari wrote: Hello everyone. I am kind of new to python so pardon me if i sound stupid. I have to find out the last M digits of expression.One thing i can do is (A**N)%M but my A and N are too large (10^100) and M is less than 10^5. The other approach was repeated squaring and taking

Re: Last M digits of expression A^N

2010-02-05 Thread Mensanator
On Feb 5, 2:18 pm, Mark Dickinson wrote: > On Feb 5, 8:14 pm, mukesh tiwari wrote: > > > Hello everyone. I am kind of new to python so pardon me if i sound > > stupid. > > I have to find out the last M digits of expression.One thing i can do > > is (A**N)%M but my  A and N are too large (10^100)

Re: Last M digits of expression A^N

2010-02-05 Thread Gerald Britton
On Fri, Feb 5, 2010 at 3:14 PM, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my  A and N are too large (10^100) and M is less than > 10^5. The other appr

Re: Last M digits of expression A^N

2010-02-05 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my  A and N are too large (10^100) and M is less than > 10^5. The other approach   was  r

Last M digits of expression A^N

2010-02-05 Thread mukesh tiwari
Hello everyone. I am kind of new to python so pardon me if i sound stupid. I have to find out the last M digits of expression.One thing i can do is (A**N)%M but my A and N are too large (10^100) and M is less than 10^5. The other approach was repeated squaring and taking mod of expression. Is t