• 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整除

  • 相关阅读:
    HDU 1269 迷宫城堡 tarjan算法求强连通分量
    hrbust 1721 A + B = 0 map的应用
    关于vis标记
    poj 1703
    poj1961 kmp
    acm poj1260 dp
    矩阵链乘 hrbust 1600
    单源最短路径 hdu 2066
    最小生成树
    多维背包 hrbudt 1335 算法与追MM
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4723631.html
Copyright © 2020-2023  润新知