比赛 位运算及及其应用题单 评测结果 AAAAA
题目名称 64位整数乘法 最终得分 100
用户昵称 dy 运行时间 0.015 s
代码语言 C++ 内存使用 3.35 MiB
提交时间 2025-01-25 15:29:11
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long

ull solve(ull a,ull b,ull p)
{
    ull res=0;
    while(b)
    {
        if(b&1)
        {
            res = (res+a)%p;  
        }
        b>>=1;
        a = (a+a)%p;
    }
    return res;
}
int main()
{
    freopen("64mul.in","r",stdin);
    freopen("64mul.out","w",stdout);
    ull a,b,p;
    cin>>a>>b>>p;
    cout<<solve(a,b,p);
	return 0;
}