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

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

思路:1.九余数定理  一个数的n的树根=(n-1)%9+1

2.N个整数的树根的乘机总值=每个项元素的树根的乘积

3.分步求余

#include<cstdio>
#include<cmath>
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
int m=n;
int i;
int ans=;
m=(m-)%+;//先把底数m求树根,根据 N个整数的乘积带的树根=每项元素的树根的乘积
for(i=;i<=n;i++)
ans=(ans*m-)%+;//分步求余
printf("%d\n",ans);
}
}

Eddy's digital Roots的更多相关文章

  1. HDU 1163 Eddy's digital Roots

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

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

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

  3. HDU-1163 Eddy's digital Roots(九余数定理)

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

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

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

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

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

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

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

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

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

  8. HDU1163 - Eddy's digital Roots

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数:一个数除于9所得到的余数,即模9得到的值 求九余数: 求出一个数的各位数字之和,如果是两 ...

  9. HDU1163 Eddy&#39;s digital Roots【九剩余定理】

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

随机推荐

  1. bootstrap tab切换如何让鼠标移动自动切换内容

    bootstrap集成了很多功能,比如nav-tabs组件,可以将相似的内容集中在一个区块中展示.bootstrap tab切换默认是要点击才会切换的,如何实现鼠标移动就自动切换呢?如下图所示,光标移 ...

  2. unity3d camera.culling mask

    原地址:http://www.cnblogs.com/88999660/archive/2013/03/14/2959439.html 官方文档对CullingMask的注释只是说了通过位移运算符,可 ...

  3. Hibernate执行原生SQL返回List<Map>类型结果集

    我是学java出身的,web是我主要一块: 在做项目的时候最让人别扭的就是hibernate查询大都是查询出List<T>(T指代对应实体类)类型 如果这时候我用的联合查询,那么返回都就是 ...

  4. 部署细节回忆录(包括了nginx重启)

    (文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) $cap -T $cap deploy:setup $cap deploy           (遇 ...

  5. 写时复制技术(Copy-on-write)

    COW技术初窥:        在Linux程序中,fork()会产生一个和父进程完全相同的子进程,但子进程在此后多会exec系统调用,出于效率考虑,linux中引入了"写时复制" ...

  6. php远程抓取网站图片并保存

    以前看到网上别人说写程序抓取网页图片的,感觉挺神奇,心想什么时候我自己也写一个抓取图片的方法! 刚好这两天没什么事,就参考了网上一个php抓取图片代码,重点借鉴了 匹配img标签和其src属性正则的写 ...

  7. windows下如何对mysql进行整裤备份

    通常情况下备份一个数据库,直接单裤备份即可,更完善一点的会要求做到定时单裤备份.然而很多时候又由于裤实例是在太多,这样会导致备份非常耗时,因而有时候需要对整个数据库应用进行备份.那么在windows下 ...

  8. iOS7 和 iOS6的页面兼容问题

    ios7 的status bar变透明了,各个bar也透明了,一个controller的view占据了整个屏幕.怎么调整呢?基本的思想是把内容的坐标下移.如果仅仅把内容的y坐标下移,那么在ios6上显 ...

  9. DP:Skiing(POJ 1088)

     北大教你怎么滑雪 题目是中文的,要读懂题目其实不难 其实这道题挺经典的,我们这样想,他最终要找到一个最大值,这个时候我们就想到要用动态规划 那怎么用呢?我们同时这样想,由于滑雪的最高点我们不能立马找 ...

  10. HDU 5510 Bazinga (字符串匹配)

    题目:传送门. 题意:t 组数据,每组 n 个串,对于第 i 个串如果存在 1 到 i-1 中的某个串不是 i 的子串,那么这个第 i 个串符合题意,求 i 的最大值. 题解:KMP,AC自动机也可以 ...