直接上源代码:
#include <stdio.h>
#define N 150
int a[N];
int b[N];
int c[N];
void cheng(__int64 x, __int64 y) //进行大数乘法运算
{
int i, j;
i = 0;
while(x > 0)
{
a[i] = x % 10;
x /= 10;
i++;
}
i = 0;
while(y > 0)
{
c[i] = y % 10;
y /= 10;
i++;
}
j = 0;
while(c[j] != -1)
{
i = 0;
while(a[i] != -1)
{
b[i+j] += a[i] * c[j];
i++;
}
j++;
}
i = 0;
while(b[i] != -1)
{
if(b[i] >= 10)
{
b[i+1] += b[i] / 10;
b[i] = b[i] % 10;
}
i++;
}
}
__int64 qiuyu(__int64 z) //进行大数求余运算
{
int i = N - 1;
__int64 t = 0;
while(b[i] == 0 && i >= 0)
{
i--;
}
while(i>=0)
{
t = 10 * t + b[i];
t = t % z;
i--;
}
return t;
}
int main()
{
int i;
__int64 x, y, z;
// freopen("data1.in","r",stdin);
// freopen("data1.out","w",stdout);
while(~scanf("%I64d%I64d%I64d", &x, &y, &z))
{
if(z == 0)
{
printf("z不能为0\n");
continue;
}
for(i = 0; i < N; i++)
{
a[i] = -1;
b[i] = 0;
c[i] = -1;
}
cheng(x,y);
/*
for(i = N - 1; i >= 0; i--)
printf("%d",a[i]);
printf("\n");
for(i = N - 1; i >= 0; i--)
printf("%d",b[i]);
printf("\n");
for(i = N - 1; i >= 0; i--)
printf("%d",c[i]);
printf("\n");
*/
printf("%I64d\n",qiuyu(z));
}
return 0;
}