码迷,mamicode.com
首页 > 其他好文 > 详细

第一轮 F

时间:2014-11-09 15:21:36      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:des   io   ar   os   sp   for   on   2014   ad   

Multiple of 17
Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status

Description
Download as PDF

  Multiple of 17 

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



Problemsetter: Rujia Liu, Special Thanks: Yiming Li



/*************************************************************************
	> File Name: f.cpp
	> Author:yuan 
	> Mail: 
	> Created Time: 2014年11月09日 星期日 13时04分13秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int mat[105];
char str[105];
int ans;
int main()
{
    while(1){
        scanf("%s",str);
        if(str[0]=='0') break;
        int l=strlen(str);
        for(int i=0;i<l;i++)
        {
            mat[i]=str[i]-'0';
        }
        ans=0;
        for(int i=0;i<l-1;i++)
        {
            ans=ans*10+mat[i];
            ans=ans%17;
        }
        ans=(ans-mat[l-1]*5)%17;
        if(ans==0) printf("1\n");
        else printf("0\n");
    }
    return 0;
}

第一轮 F

标签:des   io   ar   os   sp   for   on   2014   ad   

原文地址:http://blog.csdn.net/yuanchang_best/article/details/40949123

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!