/**//****************************************************/ // 模幂运算 计算a^b mod c // 利用公式 // (a*b)mod(c) = ((a mod c )*b)mod c /**//****************************************************/ int a_b_Mod_c(int a, int b, int c) {//前提 a b c 都是正数 int digit[32]; int i, k, resualt = 1; i = 0; while(b)//把b化成2进制 { digit[i++] = b%2; b >>= 1; } //计算(a^b) mod c for(k = i-1; k >= 0; k--) { resualt = (resualt * resualt) % c; if(digit[k] == 1) { resualt = (resualt * a) % c; } } return resualt; }