swust.oj.303

来源:互联网 发布:淘宝店铺运营案例 编辑:程序博客网 时间:2024/06/05 09:02

取模(0303)

Time limit(ms): 1000
Memory limit(kb): 65535
Submission: 1658
Accepted: 534
Accepted
15级卓越班选拔C16级卓越班选拔C 14级卓越班选拔C14级卓越班选拔C

给你三个数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;}



0 0