博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1013 Digital Roots
阅读量:4484 次
发布时间:2019-06-08

本文共 1705 字,大约阅读时间需要 5 分钟。

Digital Roots

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

Total Submission(s): 59547    Accepted Submission(s): 18621

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.
 

 

Input
The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.
 

 

Output
For each integer in the input, output its digital root on a separate line of the output.
 

 

Sample Input
24
39
0
 

 

Sample Output
6
3
 

 

Source
 

 

Recommend
We have carefully selected several similar problems for you:            
 
一道水题,不过和数学有关,需要使用到一个定理,一个数 模9等于各位数字和模9,例如 33%9=6%9,输入的数字可能很大,需要使用字符串输入。
 
题意:输入一个数字,将每一位上的数字加起来,直到和为一位数时输出,否则继续将每位数字之和相加。
 
附上代码:
1 #include 
2 #include
3 #include
4 int main() 5 { 6 char a[10100]; 7 int i,n,t,s,k; 8 while(scanf("%s",a)) 9 {10 s=0;11 t=strlen(a);12 if(a[0]=='0'&&t==1)13 break;14 for(i=0; i

 

转载于:https://www.cnblogs.com/pshw/p/4763108.html

你可能感兴趣的文章
洛谷P1282 多米诺骨牌【线性dp】
查看>>
数据类型的提升(promotion)
查看>>
Thead是不能返回值的,但是作为更高级的Task当然要弥补一下这个功能。
查看>>
Python中的生成器与yield
查看>>
JQuery 的Bind()事件
查看>>
Maven 常用配置
查看>>
Objects源码解析
查看>>
video
查看>>
栈的c语言顺序实现(动态申请空间)
查看>>
【转】 Pro Android学习笔记(六七):HTTP服务(1):HTTP GET
查看>>
获取子iframe框架的元素
查看>>
WordCount bug修复录
查看>>
承载进程 (vshost.exe)
查看>>
[转]WPF MVVM 实战
查看>>
[转载] Python 标准库 urllib2 的使用细节
查看>>
Silverlight使用DataGrid的模板列(DataGridTemplateColumn)实现类似TreeListView控件的效果
查看>>
Java学习——Applet写字符串(调字体)
查看>>
react路由
查看>>
nyoj 220——推桌子——————【贪心】
查看>>
java 静态方法分析
查看>>