数论-二分快速幂(Montgomery 算法)模板

返回 a^b mod c 的值

 1 int Mont(int a, int b, int c)
 2 {
 3     int t = 1;
 4     a %= c;
 5     while (b) {
 6         if (b & 1) t = t * a % c;
 7         b >>= 1, a = a * a % c;
 8     }
 9     return t;
10 }

 

posted @ 2017-08-26 23:34  derchg  阅读(147)  评论(0编辑  收藏  举报