Eddy's digital Roots

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

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
 
题目大意:将一个数n的各位数字加起来,如果得到的是一个一位数,那么这个数就叫n的数根,如果是两位数或多位数,则重复这个过程,直到得到的数字是一位数。现在给出n,求n^n的数根。
题目解析:最终的答案是小于10的,相当于各位数的和模10,可以不转化为对9取模,当余数为0时,则相当于模10余9。这样,便转化为了求各位数的和模9。这样便能运用九余数定理了。九余数定理的内容是这样的,一个数的各位之和除以9的余数等于这个数除以9的余数。
 
代码如下:
 # include<iostream>
# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
int ans=;
for(int i=;i<=n;++i)
ans=ans*n%;
if(ans==)
printf("9\n");
else
printf("%d\n",ans);
}
return ;
}

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

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

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

  2. HDU 1163 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 【九余数定理】

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

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

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

  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. Hdu1163 Eddy's digitai Roots(九余数定理)

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

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

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

  8. Eddy's digital Roots

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

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

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

随机推荐

  1. 2016NOI冬令营day4

    上午:随机算法/近似算法与随机算法的分析方法与应用实例 不懂,完全滑水QAQ :( 下午:计算理论与NP问题 只有讲2-sat和3-sat的时候能听懂,其他的基本都在滑水:( 晚上说是什么中学生学术训 ...

  2. MongoDB ----基于分布式文件存储的数据库

    参考: http://www.cnblogs.com/huangxincheng/category/355399.html http://www.cnblogs.com/daizhj/category ...

  3. 全面理解Java内存模型(转)

    转自:http://blog.csdn.net/suifeng3051/article/details/52611310 Java内存模型即Java Memory Model,简称JMM.JMM定义了 ...

  4. MySQL笔记(五)MySQL 角色与SQL CHECK约束

    MySQL ROLE MySQL 8.0 Reference Manual  /  Security  /  MySQL User Account Management  /  Using Roles ...

  5. MySQL笔记(二)数据库对象的创建和管理

    学校用 sqlserver ,记录数据移植到 mysql 过程中的一些问题(对应数据类型,主键外键等). 索引: 查看数据的物理路径 查看表相关的信息(SHOW CREATE TABLE.DESC) ...

  6. bzoj 2118 墨墨的等式 - 图论最短路建模

    墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值范围,求出有多少B可以使等式存在非负整数解. Input ...

  7. Unity3D学习笔记(十九):UGUI、Image、Text、Button

    UGUI:Unity官方最新,与NGUI同源 UI:User Interface(用户的操作界面),图片+文字 UGUI的组件: 1.创建UGUI组件时,会默认创建Canvas(画布)和EventSy ...

  8. 【转载】TCP慢启动、拥塞避免、快速重传、快速回复

    转载自:TCP慢启动.拥塞避免.快速重传.快速回复 转自:http://blog.csdn.net/itmacar/article/details/12278769 感谢博主的辛勤成果! 为了防止网络 ...

  9. 贪心算法-Best cow line-字典序问题

    代码: #include<cstdio> #include<iostream> #include<stdlib.h> #include<string> ...

  10. Codeforces Beta Round #94 div 2 B

    B. Students and Shoelaces time limit per test 2 seconds memory limit per test 256 megabytes input st ...