Acm hdu 1163 Eddy's digital roots (number of roots, regular search)

Source: Internet
Author: User
Eddy's digital roots

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1609 accepted submission (s): 947

Problem descriptionthe 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.

Inputthe input file will contain in 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 ).

Outputoutput n ^ n's digital root on a separate line of the output.

Sample input2
4
0

Sample output4
4

Authoreddy

Recommendjgshining many solutions: http://blog.csdn.net/iamskying/article/details/4738838http://hi.baidu.com/zf2650/blog/item/bd13eeac26a776054a36d65a.htmlhttp://hi.baidu.com/yzy%D1%EE%D7%D3%D1%DC/blog/item/4cbe340742747b71030881c7.html
 # Include  <  Stdio. h  >  
Int Main ()
{
Int N;
Char S [ 20 ] = " 914942971915947978 " ;
While (Scanf ( " % D " , & N), n)
{
Printf ( " % C \ n " , S [n % 18 ]);
}
Return 0 ;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.