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-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 :

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 anand.shash...@gmail.comwrote: Yes, it can be done. Have a look at :

Re: Last M digits of expression A^N

2010-02-06 Thread Dave Angel
monkeys paw wrote: div class=moz-text-flowed style=font-family: -moz-fixedmukesh 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

Re: Last M digits of expression A^N

2010-02-06 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com 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

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

Re: Last M digits of expression A^N

2010-02-05 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com 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

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 mukeshtiwari.ii...@gmail.com 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

Re: Last M digits of expression A^N

2010-02-05 Thread Mensanator
On Feb 5, 2:18 pm, Mark Dickinson dicki...@gmail.com wrote: On Feb 5, 8:14 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com 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