UVA11879 Multiple of 17【模算术】

Theorem: If you drop the last digit d of an integer n (n ≥ 10), subtract 5d from theremaining 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 ≤ n ≤ 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

问题链接UVA11879 Multiple of 17
问题简述:给定若干整数,最多可能有100位,如果整数是17的倍数则输出1,否则输出0。
问题分析:大数模除问题,需要了解模除定律,同时也需要了解记数法原理。简单题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11879 Multiple of 17 */

#include <bits/stdc++.h>

using namespace std;

const int N = 100;
char s[N + 1];

int main()
{
    while(~scanf("%s", s)) {
        if(s[0] == '0' && s[1] == '\0') break;

        int ans = 0;
        for(int i = 0; s[i]; i++)
            ans = (ans * 10 + s[i] - '0') % 17;

        printf(ans ? "0\n" : "1\n");
    }

    return 0;
}
上一篇:shiro中多用户的登陆页面(multiple login pages)配置


下一篇:dubbo源码阅读-配置(三)之属性配置