题目
题解思路
log级别的运算
和快速幂类似 将 b不断分两半 分不了时就加上底数
贴上板子
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
const int INF = 0x3f3f3f3f;
long long gsc(long long a ,long long b ,long long mod )
{
long long ans = 0 ;
while( b )
{
if ( b & 1 )
ans = ( ans + a )% mod ;
a = ( a + a )% mod ;
b >>= 1 ;
}
return ans ;
}
int main ()
{
ios::sync_with_stdio(false);
long long t1,t2,t3;
cin>>t1>>t2>>t3;
cout<<gsc(t1,t2,t3)<<"\n";
return 0 ;
}