超大范围幂运算

TLE 40
题目描述:
有 3 个整数a,b,c,求(a ^b) mod c

输入格式:
第一行包含一个整数T,表示测试数据组数。
对于每组测试数据,包含 3 个整数a,b,c

输出格式:
对于每组测试数据,输出一个整数表示答案。

Intput 1

6
0 0 1
0 0 100
2 5 17
0 10 100
100 0 1000000000000000000
114 514 1919810

Output1

0
1
15
0
1
290606 

最后附上代码:

#include <bits/stdc++.h>
//#define DEBUG
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
using namespace std;

ll T,a,b,c,ans =1;

void solve() {
	cin >> T;
	while (T--) {
		ans = 1;
		cin >> a >> b >> c;
		for (int i =1;i <= b;i++) ans *= a,ans %= c;
		cout << ans %c << endl;
	}
#ifdef DEBUG

#endif
}

int main() {
	close;
	solve();
	return 0;
}
1 个赞

@yhxyd0104 这题快速幂呀

会了,会了。
A了

@稻叶昙 关帖