给你三个数X(1<=X<=10^100)、Y(1<=Y<=10^8)、Z(1<=Z<=10^4),你能计算出X^Y%Z的值吗?
Description输入三个如上所描述的数X、Y、Z。多组输入。
Input输出X^Y%Z的值。
Output 2 3 5 12345 2345 345 123456789123456789 19234321 2341 Sample Input 3 240 1825 #include <iostream> #include <stdio.h> #include<string.h> using namespace std; int main() { char x[100]; int y, z; while (cin >> x >> y >> z) { int t = 0; for (int i = 0; i < strlen(x); i++) { t = (t * 10 + x[i] - '0') % z; }//我也很迷啊,不知道这里是什么原理 int ans = 1; while (y) { if (y % 2) ans = (ans*t) % z; y = y / 2; t = (t*t) % z; }//快速幂 cout << ans << endl; } return 0; }