数字整除


数字整除
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 72, Accepted users: 66
Problem 10932 : No special judgement
Problem description
  定理:把一个至少两位的正整数的个位数字去掉,再从余下的数中减去个位数的5倍。当且仅当差是17的倍数时,原数也是17的倍数 。

比如,34是17的倍数,由于3-20=-17是17的倍数;201不是17的倍数。由于20-5=15不是17的倍数。

输入一个正整数n。你的任务是推断它是否是17的倍数。



Input
  输入文件最多包括10组測试数据,每一个数据占一行。仅包括一个正整数n(1<=n<=10100),表示待推断的正整数。n=0表示输入结束,你的程序不应当处理这一行。
Output
  对于每组測试数据,输出一行,表示对应的n是否是17的倍数。1表示是。0表示否。

Sample Input
34201209876541317171717171717171717171717171717171717171717171717180
Sample Output
1010



</pre><pre name="code" class="cpp">#include<stdio.h>
#include<string.h>
int main()
{
	int a,i;
	char s[105],f;
	while(scanf("%s",s))
	{
		int b=0,g=0,j=0;
		if(s[0]=='0')
			break;
		a=strlen(s);
		if(a>=4)
		{
			for(i=a-4;i<a-1;i++)
			{
				g=g*10+s[i]-'0';
			}
			g=g-(s[a-1]-'0')*5;
			for(i=0;i<a-4;i++)
			{
				b=(s[i]-'0'+b*10)%17;
			}
			b=b*1000;
			b=(b+g)%17;
			if(b==0)
				printf("1
");
			else
				printf("0
");
		}
		else
		{
			if(a==1)
			{
				printf("0
");
			}
			else
			{
				if(a==2)
				{
					g=(s[0]-'0')-(s[1]-'0')*5;
					if(g<0)
						g=-g;
					if(g%17==0)
					   printf("1
");
					else
					  printf("0
");
				}
				if(a==3)
				{
					g=(s[1]-'0')-(s[2]-'0')*5+(s[0]-'0')*10;
					if(g<0)
						g=-g;
					if(g%17==0)
					   printf("1
");
					else
					  printf("0
");
				}
			}
		}
		j++;
		if(j==10)
			break;
	}
	return 0;
}



原文地址:https://www.cnblogs.com/yjbjingcha/p/6932715.html