做不出来 借用别人的代码 这里用到了快速幂
先是用了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
快速幂的一些技巧和取模
c++中*和&的用法 从位运算散发出来的
https://blog.csdn.net/caozixuan98724/article/details/73395598/
原文:https://www.cnblogs.com/luolinjin/p/12741383.html