For last k digits
int foo(int n, int k)
{
int m=1;
for(; k > 0; k--) m*=10;
int r=1, t=n % m;
while(n)
{
if (n % 2)
r = r * t % m;
t = t * t % m;
n >>= 1;
}
return r;
}
On Sat, Nov 21, 2009 at 9:44 AM, Siddharth Prakash Singh
<[email protected]>wrote:
> Can anybody suggest an algorithm to find first and last k digits of
> n^n.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=.
>
>
>
--
<<Bharath>>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" 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/algogeeks?hl=.