AcWing 90. 64位整数乘法

求a*b%p的值

0<a,b,p<1e18;

原题链接

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int main()
{
    ull a,b,c,ans=0;
    cin>>a>>b>>c;
    a%=c,b%=c;
    
    while(b)
    {
        if(b&1)ans=(ans+a)%c;
        b=b>>1;
        a=a<<1;
        a%=c;
    }
    cout<<ans;
    return 0;
}

 

posted @ 2021-01-19 15:12  君与  阅读(52)  评论(0)    收藏  举报