1 //字符串的乘法 2 string multi(string a, string b){ 3 int i, j, arr[200], len = a.length() + b.length(); 4 memset(arr, 0, sizeof arr); 5 reverse(a.begin(), a.end()); 6 reverse(b.begin(), b.end()); 7 for (int i = 0; i<a.length(); i++) 8 for (int j = 0; j<b.length(); j++) 9 arr[i + j] += (a[i] - '0')*(b[j] - '0'); 10 for (int i = 0; i<len; i++){ 11 arr[i + 1] += arr[i] / 10; 12 arr[i] %= 10; 13 } 14 string ret = string(len, '0'); 15 for (int i = 0; i<len; i++) 16 ret[i] += arr[i]; 17 reverse(ret.begin(), ret.end());//翻转 18 return ret; 19 } 20 21 //x ^ n 22 string Str_Pow(string x, int p){ 23 string ret = "1"; 24 while (p){ 25 if (p & 1) ret = multi(ret, x); 26 x = multi(x, x); 27 p >>= 1; 28 } 29 return ret; 30 }