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次方的数根。

数根:即某数字的每一位上的数字之和,如果和大于等于10,重复每一位上的数字之和,直到每一位上的数字之和是个位数。则这个个位数就是这个数字的数根。

九余数定理:

一个数对九取余,得到的数称之为九余数;

一个数的九余数 等于 它的各个数位上的数之和的九余数!

例:

5^5=3125

3+1+2+5=11

1+1=2(digital Roots)

3125%9=2;

一个数对9取余就等于它的个位数字之和对9取余就等于数根对9取余。

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
if(n==0){
return ;
}
int m = 1;
for(int i=0;i<n;i++){
m=(m*n)%9;
}
if(m==0){
System.out.println(9);
}else{
System.out.println(m);
}
}
}
}

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

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

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

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

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

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

  7. HDU-1163 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. XML FREESWITCH APPLICATION 实现

    XML XML在FS(FreeSwitch)中进行了大量的使用,其中dialplan就是其中非常主要的一快内容.通过下面的描述,我们可以知道在执行XML中的语句: <action applica ...

  2. Android Monkey具体解释

    Monkey是一个执行在Android设备或者虚拟机上的程序,它能随机模拟一系列用户的操作.点击,滑动,能够用它来做压力測试. 在Monkey执行的过程中,它会产生并发送一系列的事件给系统,而且监听系 ...

  3. Robotium API -- click/clickLong操作

           click&clickLong方法(点击/长按事件)        ArrayList<android.widget.TextView> clickList(int ...

  4. [AngularJS] Services, Factories, and Providers -- Service vs Factory

    Creating a Service: Before actual create an angular service, first create a constructor in Javascrip ...

  5. EEPlat 的 后台业务处理模型

    后台处理包括数据处理.业务逻辑及业务流程等服务端操作的部分.相关的元模型包括业务对象元模型.业务对象属性元模型.服务元模型.參数元模型.业务规则元模型.工作流元模型.例如以下图所看到的:   业务对象 ...

  6. HNC-局部联想脉络

    局部联想脉络 概念分为:抽象概念.具体概念 对抽象概念用 五元组 和 语义网络 表达 对具体概念用 挂靠展开近似 表达 五元组:动态.静态.属性.值.效应.(u,g,u,z,r),用于表达抽象概念的外 ...

  7. 第二章:开始开发mod前你需要知道的一些事情

    <基于1.8 Forge的Minecraft mod制作经验分享> 是的童鞋,别着急.不管我写的再认真也不可能面面俱到,那么如果遇到了什么问题怎么办呢?所以咱必须先掌握一些基础的东西,这样 ...

  8. apache的500错误是写到哪个文件里面

    apache的500错误是写到哪个文件里面

  9. mysql的perror

    eg: 执行:perror 1064 返回:MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d           ...

  10. JS中window.showModalDialog()详解 HTML DOM open() 方法

    window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框. window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框.  ...