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被九整除;得证;
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
int quickpow(int a,int b,int c)
{
int ans=;
while(b)
{
if(b&)
{
ans*=a;
ans%=c;
}
b>>=;
a*=a;
a%=c;
}
return ans==?:ans;
}
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
if(!x)break;
printf("%d\n",quickpow(x,x,));
}
return ;
}
  

hdu 1163 九余数定理的更多相关文章

  1. hdu 1163 Eddy's digital Roots 【九余数定理】

    http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...

  2. HDOJ 1163 Eddy's digital Roots 九余数定理+简单数论

    我在网上看了一些大牛的题解,有些知识点不是太清楚, 因此再次整理了一下. 转载链接: http://blog.csdn.net/iamskying/article/details/4738838 ht ...

  3. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  4. HDU1013,1163 ,2035九余数定理 快速幂取模

    1.HDU1013求一个positive integer的digital root,即不停的求数位和,直到数位和为一位数即为数根. 一开始,以为integer嘛,指整型就行吧= =(too young ...

  5. HDU——1013Digital Roots(九余数定理)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. hdu-1163(九余数定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163 思路: 九余数定理:一个数对九取余的结果叫做九余数, 一个数的各个位数相加的得到的小于10的数也 ...

  7. HDU 1163 Eddy's digital Roots(模)

    HDU 1163 题意简单,求n^n的(1)各数位的和,一旦和大于9,和再重复步骤(1),直到和小于10. //方法一:就是求模9的余数嘛! (228) leizh007 2012-03-26 21: ...

  8. Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. HDU1163【九余数定理】【水题】

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

随机推荐

  1. C# 计算当前时间距离今晚00:00:00还有多少分多少秒

    .net 计算当前时间距离今晚00:00:00还有多少分多少秒 string dateDiff = null;//获取当前时间 DateTime DateTime1 = DateTime.Now; / ...

  2. 【BZOJ2300】[HAOI2011]防线修建 set维护凸包

    [BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...

  3. ScrollView 设置滚动是否可用

    extends:http://stackoverflow.com/questions/5763304/disable-scrollview-programmatically , http://stac ...

  4. R的grep和grepl

    grep(pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE, ...

  5. IT求职部分网站汇总

    哪合伙:http://nahehuo.com/ 过来人:http://www.guolairen.com/ 智联:www.zhaopin.com 前程:www.51job.com 中华英才:www.c ...

  6. poj1463 Strategic game【树形DP】

    Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 9582   Accepted: 4516 De ...

  7. Python开发【模块】:M2Crypto RSA加密、解密

    M2Crypto 模块 快速安装: # 环境centos7.0,提前装好openssl(自行百度安装),windows装不上,暂不考虑了 [root@localhost ~]# pip install ...

  8. python面向对象(类和对象及三大特性)

    类和对象是什么 创建类 新式类 和 经典类 面向对象三大特性 继承 封装 多态   面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...

  9. 线性表:实现单链表和子类栈(Stack)及单向队列(Queue) [C++]

    刚刚开始学习c++.之前c的内容掌握的也不多,基本只是一本概论课的程度,以前使用c的struct写过的链表.用python写过简单的数据结构,就试着把两者用c++写出来,也是对c++的class,以及 ...

  10. uva11090 Bellman-Ford 运用

    给定一一个n个点m条边的加权有向图, 平均值最小的回路. 二分答案,对于每个二分的mid 做一次Bellman-Fprd , 假设有k条边组成的回路. 回路上各条边的权值为  w1 , w2 ..wk ...