82ptsTLE求助
查看原帖
82ptsTLE求助
1074084
asd890123楼主2024/8/11 20:42

用正解AC过,学习了十进制快速幂就想换一种做法,O(log⁡10b)O(\log_{10}b),最多2×1072 \times 10^7,当然常数不小,但是带上常数也就4×1084 \times 10^8左右,为何TLETLE,codecode:

#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)?

2024/8/11 20:42
加载中...