1 条题解
-
0
方法一(必学):模仿快速幂原理,把b二进制分解
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL qmul(LL a, LL b, LL P) { LL ret=0;a%=P; for(;b;b>>=1) { if(b%2==1)ret=(ret+a)%P; a=a*2%P; } return ret; } int main() { LL a, b, P;scanf("%lld%lld%lld", &a, &b, &P); LL ans=qmul(a, b, P); printf("%lld\n", ans); return 0; }方法二(必学):快读+快写+__int128
#include<bits/stdc++.h> using namespace std; typedef __int128 LL; template<typename T>void qr(T& x) { x=0;int f=1;char c=getchar(); for(;!isdigit(c);c=getchar())if(c=='-')f=-1; for(; isdigit(c);c=getchar())x=x*10+c-48; x=x*f; } template<typename T>void qw(T x) { if(x<0)putchar('-'),x=-x; if(x/10)qw(x/10); putchar(x%10+48); } int main() { LL a, b, P;qr(a);qr(b);qr(P); LL ans=a*b%P; qw(ans); return 0; }
- 1
信息
- ID
- 1112
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- 5
- 标签
- 递交数
- 176
- 已通过
- 72
- 上传者