Digital Roots


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 49834    Accepted Submission(s): 15544

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

Greater New York 2000

 





Recommend

We have carefully selected several similar problems for you:  1017 1021 1048 1016 1019

题目大意:给你一个数,若这个数的各个位数上的和为一位数字,则输出结果。

否则继续计算上一结果

的各个位数上的和。知道结果为一位数字,进行输出

思路:本以为九余数定理直接水过。发现64位数也不行~果断大数A过

#include<stdio.h>
#include<string.h>
char num[110];
int main()
{
while(~scanf("%s",num) && num[0]!='0')
{
int len = strlen(num);
int sum = 0;
for(int i = 0; i < len; i++)
{
sum += num[i] - '0';
} while(sum > 9)
{
int a = 0;
while(sum > 0)
{
a += sum % 10;
sum /= 10;
}
if(a != 0)
sum = a;
} printf("%d\n",sum);
}
return 0;
}

HDU1013_Digital Roots【大数】【水题】的更多相关文章

  1. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  2. POJ 2506 Tiling dp+大数 水题

    大致题意:现有两种方块(1X2,2X2),方块数量无限制.问用这两种方块填满2Xn的矩阵的填法有多少种. 分析:通俗点说,找规律.专业化一点,动态规划. 状态d[i],表示宽度为i的填法个数. 状态转 ...

  3. HDU-1047-Integer Inquiry(Java大数水题 &amp;&amp; 格式恶心)

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

  4. SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)

    #include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...

  5. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  6. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  7. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  8. 每日一刷(2018多校水题+2016icpc水题)

    11.9 线段树 http://acm.hdu.edu.cn/showproblem.php?pid=6315 求逆序对个数 http://acm.hdu.edu.cn/showproblem.php ...

  9. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  10. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

随机推荐

  1. 完美完全卸载Oracle 11g数据库

    Oracle 11g可在开始菜单中卸载,然后同时需要删除注册表中相关内容. 操作系统:windows10专业版. 卸载步骤: 1.停用oracle服务:进入计算机管理,在服务中,找到oracle开头的 ...

  2. android模块化app开发笔记-2插件间布局文件共享

    android编程时布局文件,图片资源等都是放在同一个文件夹下,这样照成一个问题就是我们想重用UI布局文件和图片时就还需要其分离这些资料,相信大部分android程序员都遇到过这样的问题,其痛苦程度不 ...

  3. android左右滑动加载分页以及动态加载数据

    android UI 往右滑动,滑动到最后一页就自动加载数据并显示 如图: package cn.anycall.ju; import java.util.ArrayList; import java ...

  4. SQL注入中利用XP_cmdshell提权的用法(转)

    先来介绍一下子服务器的基本情况,windows 2000 adv server 中文版,据称 打过了sp3,asp+iis+mssql .首先扫描了一下子端口,呵呵,开始的一般步骤. 端口21开放: ...

  5. VMtools安装以及设置

    一.安装VMtools 点击VMware菜单的——虚拟机——安装VMware Tools,在弹出的对话框中选择“安装”.这时,在Ubuntu下会自动加载Linux版的VMware Tools的安装光盘 ...

  6. Tsinsen A1303. tree(伍一鸣) (LCT+处理标记)

    [题目链接] http://www.tsinsen.com/A1303 [题意] 给定一棵树,提供树上路径乘/加一个数,加边断边,查询路径和的操作. [思路] LCT+传标 一次dfs构造LCT. L ...

  7. (转载)OC学习篇之---类的定义

    之前已经介绍了OC中的一个程序HelloWorld,今天我们继续学习OC中类的相关知识. OC和C的最大区别就是具有了面向对象的功能,那么说到面向对象,就不得不说类这个概念了,如果学过Java的话,那 ...

  8. 配置youcompleteme碰到的问题

    Q1: 进入vim里面后,可以使用ycm的相关命令来看到底出现啦什么问题? :Ycm YcmCompleter YcmForceCompileAndDiagnostics YcmToggleLogs ...

  9. 【Spark学习】Apache Spark集群硬件配置要求

    Spark版本:1.1.1 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4135912.html 目录 存 ...

  10. JAVA——利用wait和notify实现生产者和消费者

    经典的消费者和生产者的的实现: 注意事项: 1:在循环里面用wait(),因为当线程获得了锁,但是有可能还没有满足其他条件: 2:公用的缓冲池要用锁机制: package demo; import j ...