Eddy's digital Roots

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

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
 
九余数定理:一个数的每位数字之和等于这个数对9取余,如果等于0就是9
 
 #include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,sum,i;
while(cin>>n&&n)
{
sum=;
i=n;
while(i--)
sum=(sum*n)%;
if(sum==)
cout<<<<endl;
else
cout<<sum<<endl;
}
return ;
}
 

Eddy's digital Roots(九余数定理)的更多相关文章

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

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

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

    题目大意: 给定一个正整数,根据一定的规则求出该数的“数根”,其规则如下: 例如给定 数字 24,将24的各个位上的数字“分离”,分别得到数字 2 和 4,而2+4=6: 因为 6 < 10,所 ...

  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. HDU 1163 Eddy's digital Roots

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

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

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

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

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

  7. Eddy's digital Roots

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  8. HDU-1163Eddy's digital Roots,九余定理的另一种写法!

    下午做了NYOJ-424Eddy's digital Roots后才正式接触了九余定理,不过这题可不是用的九余定理做的.网上的博客千篇一律,所以本篇就不发篇幅过多介绍九余定理了: 但还是要知道什么是九 ...

  9. hdoj-1013-Digital Roots(九余数定理)

    题目链接 #include <iostream> using namespace std; int main() { string a; int b; ") { b = ; ;i ...

随机推荐

  1. 话说 MAX_FILE_SIZE

    PHP关于文件上传部分,特别提到表单隐藏域:MAX_FILE_SIZE,意思是接收文件的最大尺寸.文档中给出的例子如下: <form enctype="multipart/form-d ...

  2. Azure上A/D系列虚拟机到DS系列迁移(1)

    有一些用户在刚开始的时候创建了A7,D14等虚拟机来跑一些IO要求比较高的应用,比如Oracle数据库,MySQL数据库,等到用户量上来之后,性能不够,需要升级数据磁盘到SSD固态硬盘,但是问题是: ...

  3. c#POST请求和接收post请求

    c# post请求发送数据 /// <summary> /// POST请求 /// </summary> /// <param name="url" ...

  4. 51单片机实现对24C02进行页写、顺序读取并显示验证

    //************************************************************************************* //**程序名称:51单 ...

  5. 【转】飞凌嵌入式(Forlinx)TE/OK6410内核编译:“make: arm-none-linux-gnueabi-gcc:命令未找到”

    原文网址:http://www.xuebuyuan.com/1104711.html Ubuntu10.04下编译飞凌嵌入式(Forlinx)TE/OK6410开发板提供的内核2.6.36 本以为按照 ...

  6. 《如何让TT T4模板输出多个文件(VS2010中)》-- access911.net 文章

    <如何让TT T4模板输出多个文件(VS2010中)>-- access911.net 文章   问题:   VS2010中自带的 TT 模板功能挺好用,但是如何定义其输出的目录,或者如何 ...

  7. Django的安装配置和开发

    参考:<Django Web开发指南> Django的安装配置 1.https://www.djangoproject.com/download/下载Django-1.5.1.tar.gz ...

  8. Zookeeper 5、Zookeeper应用场景

    应用场景1 .统一命名服务 » 分布式应用中,通常需要有一套完整的命名规则,既能够产生唯一的名称又便于人识别和记住,通常情况 下用树形的名称结构是一个理想的选择,树形的名称结构是一个有层次的目录结构, ...

  9. Ajax跨域访问解决办法

    方法1. jsonp实现ajax跨域访问示例 jsp代码: <body> <input type="button" onclick="testJsonp ...

  10. LinearGradient线性渲染

    import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; impor ...