用正解AC过,学习了十进制快速幂就想换一种做法,O(log10b),最多2×107,当然常数不小,但是带上常数也就4×108左右,为何TLE,code:
#include <iostream>
#include <cstring>
const int N = 20000005;
char b[N];
int qpow(int a,char* b,int p){
int ans = 1;
for (int i = strlen(b + 1);i;i--){
int tmp = a;
for (int j = 1;j <= b[i] - '0';j++) ans = (long long)ans * a % p;
for (int j = 1;j <= 9;j++) a = (long long)a * tmp % p;
}
return ans;
}
int main(){
std::cin.tie(0)->sync_with_stdio(0);
int a,m;
std::cin >> a >> m >> b + 1;
std::cout << qpow(a,b,m) << '\n';
return 0;
}
我写过正解的,所以不用给我正解代码,就想知道这能不能过,为什么不能过(82pts,TLE on #1,#2)?