HDU5373——同余模——The shortest problem

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

/************************************************
* Author        :Powatr
* Created Time  :2015-8-12 9:23:18
* File Name     :1003.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int sum(int x)
{
    int m = 0;
    while(x){
        m += x%10;
        x/=10;
    }
    return m;
}

int fact(int x)
{
    int m = 1;
    for(int i = 1; i <= x; i++)
        m *= 10;
    return m;
}

int bit(int x)
{
    int m = 0;
    while(x){
        m++;
        x/=10;
    }
    return m;
}
int main(){
    int n, m;
    int ss;
    int su;
    int cas = 1;
    while(~scanf("%d%d", &n, &m)){
        if(n == m && n == -1) break;
        ss = n%11;
        su = sum(n);
            for(int i = 1; i <= m; i++){
              //  printf("%d
", ss*fact(bit(su)));
                ss = (ss*fact(bit(su)) + su) % 11;
                su += sum(su);
            }
            printf("Case #%d: ", cas++);
            if(ss == 0) printf("Yes
");
            else printf("No
");
    }
    return 0;
}
                  

  还有一个性质:被11整除的数奇偶位和之差能被11整除

原文地址:https://www.cnblogs.com/zero-begin/p/4723631.html