(一)题目:a^b%p
#include <iostream>
#define LL long long
using namespace std;
int main()
{
LL a,b,p;
cin >> a >> b >> p;
LL res = 1 % p;
while (b){
if(b & 1) res = res * a%p;
a = a * a % p;
b >>=1;
}
cout << res << endl;
return 0;
}
(二)题目:a*b %p
#include <iostream>
#define ULL unsigned long long
using namespace std;
int main()
{
ULL a,b,p;
cin >> a >> b >> p;
ULL res = 0;
while(b){
if(b & 1) res = (res + a) % p;
b >>= 1;
a = a * 2 % p;
}
cout << res;
return 0;
}