Multiple of 17

题目大意:所给数n,去掉最后一位数a,并减去5*a所得的值是否能被17整除?

Description 

Theorem: If you drop the last digit d of an integer n (n$ \ge$10), subtract 5d from the remaining integer, then the difference is a multiple of 17 if and only if n is a multiple of 17.

For example, 34 is a multiple of 17, because 3-20=-17 is a multiple of 17; 201 is not a multiple of 17, because 20-5=15 is not a multiple of 17.

Given a positive integer n, your task is to determine whether it is a multiple of 17.

Input 

There will be at most 10 test cases, each containing a single line with an integer  n (  1$ \le$n$ \le$10100). The input terminates with  n = 0, which should not be processed.

Output 

For each case, print 1 if the corresponding integer is a multiple of 17, print 0 otherwise.

Sample Input 

34
201
2098765413
1717171717171717171717171717171717171717171717171718
0

Sample Output 

1
0
1
0

#include<stdio.h>
#include<string.h>
#define M 205

char s[M];
int a[M];

int main(){
	int i,n,ans;
	while(scanf("%s",s) && s[0]!='0'){
		ans=0;
		n=strlen(s);
		for(i=0;i<n;i++){
			a[i]=s[i]-'0';
		}
		for(i=0;i<n-1;i++){
			ans=ans*10+a[i];
			ans=ans%17;
		}
		ans=(ans-a[i]*5)%17;
		if(ans) puts("0");
		else puts("1");
	}
	return 0;
}
/*
34
201
2098765413
1717171717171717171717171717171717171717171717171718
0
Sample Output 

1
0
1
0
*/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值