FAFU-OJ 1002 简单吗?

直接上源代码:

 

#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;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值