Home > Backend Development > PHP Tutorial > http://acm.zznu.edu.cn/problem.php?id=1329

http://acm.zznu.edu.cn/problem.php?id=1329

WBOY
Release: 2016-06-23 13:36:23
Original
876 people have browsed it

1329: 数字整除

题目描述

定理:把一个至少两位的正整数的个位数字去掉,再从余下的数中减去个位数的5倍。当且仅当差是17的倍数时,原数也是17的倍数 。

例如,34是17的倍数,因为3-20=-17是17的倍数;201不是17的倍数,因为20-5=15不是17的倍数。输入一个正整数n,你的任务是判断它是否是17的倍数。

输入

输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1

输出

对于每组测试数据,输出一行,表示相应的n是否是17的倍数。1表示是,0表示否。

样例输入

34201209876541317171717171717171717171717171717171717171717171717180
Copy after login

样例输出

1010
Copy after login

#include
#include
#define N 1010

int main()
{
int i, x;
char s[N];
while(scanf("%s", s), strcmp(s, "0"))
{
x = 0;
for(i = 0 ; s[i] != '\0' ; i++)
{
x = x * 10 + (s[i] - '0');
if(x > 17)
x %= 17;
}
if(x % 17 == 0)
printf("1\n");
else
printf("0\n");
}
return 0;
}//大数取余可以用这种方法处理

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template