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

1329: 数字整除

题目描述

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

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

输入

输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1<=n<=10100),表示待判断的正整数。n=0表示输入结束,你的程序不应当处理这一行。

输出

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

样例输入

34
201
2098765413
1717171717171717171717171717171717171717171717171718
0

样例输出

1
0
1
0

#include<stdio.h>
#include<string.h>
#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;
}//大数取余可以用这种方法处理

时间: 2024-08-07 16:59:31

http://acm.zznu.edu.cn/problem.php?id=1329的相关文章

http://acm.gdufe.edu.cn/Problem/read/id/1007

递推题目系列之一涂色问题 Time Limit: 2000/1000ms (Java/Others) Problem Description 有排成一行的n个方格,用红(Red).粉(Pink).绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法. Input: 输入数据包含多个测试实例,每个测试实例占一行,由一个整数N组成,(0<n<=50). Output: 对于每个测试实例,请输出全部的满足要求的涂法,每个实例的输出占一行.

http://acm.zzuli.edu.cn/problem.php?id=1654

1654: D:数塔塔塔塔塔塔 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 154  Solved: 55SubmitStatusWeb Board Description Input Output Sample Input 1 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 Sample Output 30 (0,0)-->(1,0)-->(2,0)-->(3,1)-->(4,1) #include<std

KMP(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&amp;problemid=2772)

#include <stdio.h>#include <string.h>#include <stdlib.h>char a[1000001],b[1000001];int next[1000001];int l,l2;void Getnext(){ int i=0; int j=-1; next[0]=-1; while(i<l2) { if(-1==j||b[i]==b[j]) { i++; j++; next[i]=j; } else j=next[j];

http://acm.hdu.edu.cn/showproblem.php?pid=2825

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2825 题目: Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6862    Accepted Submission(s): 2279 Problem Description Liyuan lives in a

HDU-4632 http://acm.hdu.edu.cn/showproblem.php?pid=4632

http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里有多少个回文串,那首先dp[i][j]=dp[i+1][j]+dp[i][j-1],但是dp[i+1][j]和dp[i][j-1]可能有公共部分,所以要减去dp[i+1][j-1]. 如果str[i]==str[j]的话,还要加上dp[i+1][j-1]+1. 但是自己却是这样想的,把每个区间都要看

[ACM] 1016 Prime Ring Problem (深度优先搜索)

Prime Ring Problem Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle

POJ3156 暑假集训-最短路H题floyd http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank

  http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank#include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<limits.h> #include<mat

codevs http://www.codevs.cn/problem/?problemset_id=1 循环、递归、stl复习题

12.10高一练习题 1.要求: 这周回顾复习的内容是循环.递归.stl. 不要因为题目简单就放弃不做,现在就是练习基础. 2.练习题: (1)循环   题目解析与代码见随笔分类  NOI题库 http://noi.openjudge.cn/ch0106/    10-15题 http://noi.openjudge.cn/ch0105/     37-45题 http://noi.openjudge.cn/ch0107/     28-35题 (2)递归   题目解析与代码见随笔分类 递归 h

HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少是多少? 因为每次相邻的交换操作最多只能减少一个逆序对,所以最多可以减少k个逆序对,所以我们只要求出原来的序列有多少个逆序对然后减去k再跟0取较大的就可以了. 因为数据范围是10的五次方,所以暴力求肯定会TLE,所以要用n*logn算法求逆序对,n*logn算法有几种可以求逆序对的: 线段树,树状数