找传奇、传世资源到传世资源站!

快速幂算法(binary

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

math函数库中的pow函数效率低,如代码所展示的多种幂运算算法,可显著降低时间复杂度,提高运行效率

快速幂算法,递归与循环int main(){ unsigned long long qick_pow1(unsigned long long a, unsigned long long n, unsigned long long p); unsigned long long qick_pow2(unsigned long long a, unsigned long long n, unsigned long long p); unsigned long long qick_pow3(unsigned long long a, unsigned long long n, unsigned long long p); unsigned long long a, n, p; scanf("%llu %llu %llu", &a, &n, &p); printf("%llu\n", qick_pow1(a, n, p)); printf("%llu\n", qick_pow2(a, n, p)); printf("%llu\n", qick_pow3(a, n, p)); printf("%llu\n", (unsigned long long)pow(a, n) % p);}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复