您的位置:首页 > 其它

toj 4607 Multiple of 17

2016-08-09 11:35 357 查看

toj 4607 Multiple of 17

时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte

总提交: 33 测试通过:17

描述

Theorem: If you drop the last digit d of an integer n (n10), 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.

输入

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

输出

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

样例输入

34

201

2098765413

1717171717171717171717171717171717171717171717171718

0

样例输出

1

0

1

0

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
char s[10000];
while(scanf("%s", s) && (s[0] != '0'))
{
int sum = 0;
for(int i = 0; s[i] != '\0'; i++)
{
sum = (sum * 10 +s[i] - '0');

sum %= 17;

}
if(sum == 0)
printf("1\n");
else
printf("0\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息