杭电oj(Java版)——1013 Digital Roots
来源:互联网 发布:淘宝模板设计师赚钱吗 编辑:程序博客网 时间:2024/05/16 09:02
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 77361 Accepted Submission(s): 24179
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.
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
24390
Sample Output
63import java.math.BigInteger;import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner scanner = new Scanner(System.in);BigInteger b;while (scanner.hasNext()) {b = scanner.nextBigInteger();if (b.intValue()==0) {break;} else if (b.mod(new BigInteger(String.valueOf(9))).intValue()==0){System.out.println(9);} else {System.out.println(b.mod(new BigInteger(String.valueOf(9))));}}}}
0 0
- 杭电oj(Java版)——1013 Digital Roots
- 杭电OJ--1013 Digital Roots
- 杭电oj Problem-1013 Digital Roots
- 杭电acm—1013 Digital Roots
- 杭电1013——Digital Roots(简单题)
- 杭电 1013 Digital Roots
- 杭电1013 Digital Roots
- Digital Roots 杭电1013
- 杭电1013 Digital Roots
- 杭电1013 Digital Roots
- 杭电OJ(HDOJ)1013题:Digital Roots(数值分解)
- 【杭电oj】1013 - Digital Roots(数论 - 九余定理,好题)
- 杭电 Digital Roots
- 1013—Digital Roots
- 杭电 1013 Digital Roots (栈的做法)
- 杭电 1013 Digital Roots (字符串数组)
- 杭电ACM 1013 Digital Roots
- 杭电acm 1013 Digital Roots
- Java 8
- 题目1086:最小花费
- 未完成, (学习学长的处理年月日的方式)
- jquery事件绑定
- MySQL (7) 索引基础
- 杭电oj(Java版)——1013 Digital Roots
- Picasso从使用到源码解析
- #python学习笔记#assert
- 西游伏妖篇 Journey to the West: Demon Chapter
- 竖排显示诗歌的一种思路
- 如何搭建量化投资研究系统?(数据篇)
- Android蓝牙连接打印
- jvm java 栈与堆知识
- 我的第一篇博客,java面向对象来解决简单的问题--杭电2001