2010湖南省赛C题(数字整除)

本文提供了一种处理大整数取模运算的有效方法,并通过C++代码实现了具体算法。该算法利用字符串存储大整数并逐位进行计算,有效避免了直接使用整数类型可能导致的溢出问题。

大整数取模,脑袋怎么就不开窍呢

//我太愚蠢啦
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char s[200];
int main()
{
	while(gets(s))
	{
		if(strcmp(s,"0")==0) break;
		int i;
		int len=strlen(s);
		int ou=0;
		for(i=0;i<len;i++)
		{
			ou=((ou*10)%17+(s[i]-'0')%17)%17;
		}
		if(ou==0) cout<<1<<endl;
		else cout<<0<<endl;
	}
	return 0;
}


转载于:https://www.cnblogs.com/lj030/archive/2013/01/04/3002272.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值