Pages

Wednesday, October 7, 2009

Big Mod (uva#374)

Question:

Solutions :
long bigmod(long b, long p, long m){
if(p==0)
return 1;
else if(p%2==0)
return ((bigmod(b, (p/2), m))*(bigmod(b, (p/2), m)))%m;
else return((b%m)*bigmod(b, p-1, m))%m;
}
  

No comments:

Post a Comment