首页 > 其他 > 详细

小白1-3

时间:2020-04-21 21:09:04      阅读:59      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

技术分享图片

 

做不出来 借用别人的代码  这里用到了快速幂

先是用了typedef将long long变成LL避免代码繁冗

及时的对x的平方和res取模 防止这两个数的结果比mod大

另外一个技巧见第三个链接

 

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
LL mod_pow(LL x, LL n, LL mod)
{
LL res = 1;
while (n > 0)
{
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res % mod;
}
int main()
{
LL a, b, c, d, mod;
while (cin >> a >> b >> c >> d >> mod)
{
LL x = ((a % mod) * (b % mod)) % mod;
LL n = c * d;
cout << mod_pow(x, n, mod) << endl;
}
return 0;
}

 

 

下面是一些大佬的链接

关于快速幂的迭代和递归

https://blog.csdn.net/Harington/article/details/87602682

位运算的概念

https://blog.csdn.net/xiaopihaierletian/article/details/78162863

快速幂的一些技巧和取模

https://blog.csdn.net/u011815404/article/details/80920908?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-10&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-10

c++中*和&的用法 从位运算散发出来的

https://blog.csdn.net/caozixuan98724/article/details/73395598/

 

小白1-3

原文:https://www.cnblogs.com/luolinjin/p/12741383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!