zoukankan      html  css  js  c++  java
  • hdu 1163 九余数定理

    Eddy's digital Roots

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5928    Accepted Submission(s): 3270


    Problem Description
    The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

    For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.

    The Eddy's easy problem is that : give you the n,want you to find the n^n's digital Roots.
     
    Input
    The input file will contain a list of positive integers n, one per line. The end of the input will be indicated by an integer value of zero. Notice:For each integer in the input n(n<10000).
     
    Output
    Output n^n's digital root on a separate line of the output.
     
    Sample Input
    2 4 0
     
    Sample Output
    4 4
     
    Author
    eddy
    思路:求n^n对9取模,特判0的情况;
     对于那个定理的证明;
    设那个数为abcd;这个数=1000*a+100*b+10*c+d;
            a+b+c+d=这个数-9999a-99b-99c;
            由于9999a-99b-9c被九整除;得证;
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<string>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<stack>
     8 #include<cstring>
     9 #include<vector>
    10 #include<list>
    11 #include<set>
    12 #include<map>
    13 using namespace std;
    14 #define ll long long
    15 #define mod 1000000007
    16 #define inf 999999999
    17 #define esp 0.00000000001
    18 //#pragma comment(linker, "/STACK:102400000,102400000")
    19 int quickpow(int a,int b,int c)
    20 {
    21     int ans=1;
    22     while(b)
    23     {
    24         if(b&1)
    25         {
    26             ans*=a;
    27             ans%=c;
    28         }
    29         b>>=1;
    30         a*=a;
    31         a%=c;
    32     }
    33     return ans==0?9:ans;
    34 }
    35 int main()
    36 {
    37     int x,y,z,i,t;
    38     while(~scanf("%d",&x))
    39     {
    40         if(!x)break;
    41         printf("%d
    ",quickpow(x,x,9));
    42     }
    43     return 0;
    44 }
      
  • 相关阅读:
    华为精益敏捷专家:DevOps转型中的那些坑
    极致进化-敏捷进化型企业的未来畅想
    DevOps的工程化
    京东精益敏捷教练分享:敏捷助力产品创新!
    敏捷开发进度管理之燃尽图
    手把手教你进行Scrapy中item类的实例化操作
    手把手教你使用ADB卸载手机内置App软件
    手把手教你使用Python生成图灵智能小伙伴,实现工作助手/闲聊功能
    手把手教你利用Pyecharts库对IP代理数据进行数据可视化分析
    手把手教你使用Python爬取西刺代理数据(下篇)
  • 原文地址:https://www.cnblogs.com/jhz033/p/5499700.html
Copyright © 2011-2022 走看看