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. Qt 学习之路 2(55):数据库操作

    Qt 提供了 QtSql 模块来提供平台独立的基于 SQL 的数据库操作.这里我们所说的“平台独立”,既包括操作系统平台,又包括各个数据库平台.另外,我们强调了“基于 SQL”,因为 NoSQL 数据 ...

  2. hue, saturation, and brightness:色调、饱和度和亮度

    色调.饱和度和亮度(hue, saturation, and brightness)以人对红.绿.蓝(RGB)三色组合的感觉为基础.在描述阴极射线管显示器参数时,经常提到这三个专有名词.所有的颜色可以 ...

  3. 如何加固linux NFS 服务安全的方法

    NFS(Network File System)是 FreeBSD 支持的一种文件系统,它允许网络中的计算机之间通过 TCP/IP 网络共享资源.不正确的配置和使用 NFS,会带来安全问题. 概述 N ...

  4. python-随机数的产生random模块

    random模块用来产生随机数: 查看random模块的方法: import random random.__dir__ Out[39]: <function __dir__> rando ...

  5. Python学习笔记之在Python中实现单例模式

    有些时候你的项目中难免需要一些全局唯一的对象,这些对象大多是一些工具性的东西,在Python中实现单例模式并不是什么难事.以下总结几种方法: 使用类装饰器 使用装饰器实现单例类的时候,类本身并不知道自 ...

  6. python3 isinstance()判断元素是否是字符串、int型、float型

    python3 isinstance()判断元素是否是字符串.int型.float型 isinstance是Python中的一个内建函数 语法: isinstance(object, classinf ...

  7. Duilib Edit编辑框禁止输入中文的方法

    转载:http://www.myexception.cn/vc-mfc/300749.html 编辑框是供用户输入的,但有时候我们要限制用户输入的内容,比如我们不让用户输入中文,只能输入字符和数字,因 ...

  8. 【前端】javascript实现鼠标跟随特效

    实现效果: 实现代码: <!DOCTYPE html> <html> <head> <title>鼠标跟随</title> <meta ...

  9. Python3基础 函数 递归 阶乘与斐波那契数列

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. P3216 [HNOI2011]数学作业 (矩阵快速幂)

    P3216 [HNOI2011]数学作业 题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 NN 和 MM ,要求计算 Concatenate (1 .. N ...