计算(a*b)%c

来源:互联网 发布:淘宝客招代理话术 编辑:程序博客网 时间:2024/05/22 00:05

计算(a*b)%c

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <string>#include <cstring>#include <ctime>#define ms(a,b) memset(a,b,sizeof(a))using namespace std;typedef long long ll;// 计算(a*b)%c. a,b都是long long 的数, 直接相乘可能溢出的// a,b,c <2^63long long mult_mod(long long a, long long b, long long c){    a %= c;    b %= c;    long long ret = 0;    while (b)    {        if (b & 1)        {            ret += a;            ret %= c;        }        a <<= 1;        if (a >= c)        {            a %= c;        }        b >>= 1;    }    return ret;}int main(){    ll a, b, c;    while (cin >> a >> b >> c)    {        cout << mult_mod(a, b, c) << endl;    }    return 0;}


原创粉丝点击