Eddy's digital Roots

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

Total Submission(s): 5238    Accepted Submission(s): 2925

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

本题考查九余定理

#include<stdio.h>
int main(){
 int n,i,a;
 while(scanf("%d",&n),n)
 {
  a=n;
  for(i=2;i<=n;i++)
  a=a*n%9;
  if(a==0)
  printf("9\n");
  else printf("%d\n",a);
 }
 return 0;
}

Eddy's digital Roots

时间: 2024-11-05 13:33:37

Eddy&#39;s digital Roots的相关文章

HDU 1163 Eddy&#39;s digital Roots

Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5783    Accepted Submission(s): 3180 Problem Description The digital root of a positive integer is found by summing the digit

HDU1163 Eddy&#39;s digital Roots【九余数定理】

Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4436    Accepted Submission(s): 2505 Problem Description The digital root of a positive integer is found by summing the digi

Eddy&#39;s digital Roots(九余数定理)

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 digit

杭电 HDU 1163 Eddy&#39;s digital Roots

Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4904    Accepted Submission(s): 2743 Problem Description The digital root of a positive integer is found by summing the digi

hdu 1163 Eddy&#39;s digital Roots(九余数定理)

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

Eddy&#39;s digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4793    Accepted Submission(s): 2672 Problem Description The digital root of a positive integer is found by summing the digits of the integer. If

杭电 1163 Eddy&#39;s digital Roots

Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4275    Accepted Submission(s): 2404 Problem Description The digital root of a positive integer is found by summing the digi

Hdu-1163 Eddy&#39;s digital Roots(九余数定理)

题意:对于一个数,只要它不是单个数,就把它各位的数相加,直到成为单个数. 九余数定理 一个数对九取余后的结果称为九余数. 一个数的各位数字之和想加后得到的<10的数字称为这个数的九余数(如果相加结果大于9,则继续各位相加) 因为数据挺大的,不能暴力.所以可以边乘边取余.很像快速幂. 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int main(){ 6 int n; 7 while

HDU1163 Eddy&#39;s digital Roots

问题链接:HDU1013 Digital Roots.入门练习题,用C语言编写程序. 这个问题是对于输入的n,计算n^n的数根. 先看一下以下式子: 因为:(10*a+b)*(10*a+b)=100*a*a+10*2*a*b+b*b 所以右边式子的数根(中间结果,也是左边式子的数根)为:a*a+2*a*b+b*b=(a+b)*(a+b) 故:对于两位数n,n*n的数根=n的树根×n的树根. 同理可以推出,对于任意位数的n,也满足:n*n的数根=n的树根×n的树根. 程序中,实现一个计算整数数根的