| Time Limit: | 1000MS | Memory Limit: | 1000KB |
|---|---|---|---|
| Total Submissions: | 1255 | Accepted: | 212 |
Description:
题目非常的简单,输入三正整数ABC,输出(A*B)%C的值。不过这样一句scanf和一句printf就能解决的问题肯定会让这么聪明的你感觉很郁闷的,所在这里加一点点难度,测试数据里的A,B,C的值会稍大一点点,不过最大不会超过2^63。
或许,你会想用大数做,不过大数的乘和模不是很好写,那有没有其它方法呢。我想,聪明的你很快就想到的 :)
Input:
输入多组测试数据,每组一行三个正整数,A,B,C。0 < A , B , C < 2 63 。
Output:
每个测试数据一行,(A*B)%C的值。
Sample Input:
1 2 10
12 14 100
15 3 21
Sample Output:
2
68
3
Source:
#include<stdio.h>
typedef __int64 INT;
INT a,b,c,ans=0;
INT mul_mod(INT a, INT b, INT mod)
{
if(mod / a >= b)
return a * b;
return ((mul_mod(a, b >> 1, mod) << 1) + a * (b & 1)) % mod;
}
int main()
{
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
ans=((a % c) * (b % c)) % c;
printf("%I64d\n",mul_mod(a,b,c));
}
return 0;
}
\
\