Digital RootsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 57047 Accepted Submission (s): 17799
Problem DescriptionThe Digital root of a positive integer is found by summing the digits of the integer. If The resulting value is a, digit then, digit is the digital root. If The resulting value contains or more digits, those digits was summed and the process is repeated. This was continued as long as necessary to obtain a and 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 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.
Inputthe input file would contain a list of positive integers, one per line. The end of the input would be indicated by an integer value of zero.
Outputfor each integer in the input and output its digital root on a separate line of the output.
Sample Input
24390
Sample Output
63
Sourcegreater New York 2000
Recommendwe carefully selected several similar problems for you:1017 1021 1012 1018 1048
Explain the title: is to give you a number let you find the root of the number! What do you mean, roots? For example, 24 of this number of roots, is the number of 24 of each bit added up! 2+4=6 and 6 is single digit, so it is the root of 24. And then 39 this number the same way, 3+9=12 at this point we find that 12 is not a single digit, so it is not a number of root, continue to let it all the number of bits added, 1+2=3,3 is single digit, so 3 is the number of 39 root.
Number of formulas:number of a root B = (A-1)% 9 + 1Still do not understand can Baidu encyclopedia a few root, very simple mathematical definition, abbreviation natural number of a definition.
Import java.io.*;import java.math.biginteger;import java.util.*;p ublic class main{public static void Main (string[] args {//TODO auto-generated method Stubscanner input = new Scanner (system.in); while (Input.hasnext ()) {String num = Input.next (); if (Num.equals ("0")) break; BigInteger BigInteger = new BigInteger (num); BigInteger Nine = new BigInteger ("9"); BigInteger Minusone = new BigInteger ("1"); BigInteger B = Biginteger.add (minusone); b = B.mod (Nine); b = B.add (Biginteger.one); System.out.println (b);}}
Hdu-1013-digital Roots (Java && Large number && number root)