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. Bootstrap的响应式,当文字超过div长度,换行问题的处理!

    (1)overflow: hiddenoverflow 属性规定当内容溢出元素框时发生的事情.这个属性定义溢出元素内容区的内容会如何处理.hidden 表示内容会被修剪,并且剪掉的内容是不可见的. ( ...

  2. ZOJ 3745 Salary Increasing

    Description Edward has established a company with n staffs. He is such a kind man that he did Q time ...

  3. [TYVJ] P1044 数字三角形

    数字三角形 背景 Background 09年 USACO 11月月赛  铜牌第一道   描述 Description 示出了一个数字三角形. 请编一个程序计算从顶至底的某处的一条路径,使该路径所经过 ...

  4. slime+sbcl for common lisp

    sudo apt-get install slime audo apt-get install sbcl ;;sbcl+slime for common lisp ;;sudo apt-get ins ...

  5. C#开发SQLServer的Geometry和Geography存储

    原文:C#开发SQLServer的Geometry和Geography存储 SQL Server2008推出后最大的变化就是提供了支持空间数据存储的Geometry和Geography,这个也是如果将 ...

  6. ajax jquery return没有返回值

    错误写法: function editdivisionmember(division_id,users_id){ $.ajax({ type:"POST", url:"/ ...

  7. Linux系统编程(9)—— 进程之进程控制函数exec系列函数

    在Linux中,并不存在exec()函数,exec指的是一组函数,一共有6个,分别是: #include <unistd.h> extern char **environ; int exe ...

  8. bzoj2018 [Usaco2009 Nov]农场技艺大赛

    Description Input 第1行:10个空格分开的整数: N, a, b, c, d, e, f, g, h, M Output 第1行:满足总重量最轻,且用度之和最大的N头奶牛的总体重模M ...

  9. Pattern | CLiPS

    Pattern | CLiPS Pattern Pattern is a web mining module for the Python programming language. It has t ...

  10. SQL With(递归 CTE 查询)

    本文来自:http://www.cnblogs.com/smailxiaobai/archive/2012/01/16/2323291.html 指定临时命名的结果集,这些结果集称为公用表表达式 (C ...