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
一个数对九取余,得到的数称之为九余数;
一个数的九余数等于它的各个数位上的数之和的九余数!

题目大意:

给定一个正整数,根据一定的规则求出该数的“数根”,其规则如下:

例如给定 数字 24,将24的各个位上的数字“分离”,分别得到数字 2 和 4,而2+4=6;

因为 6 < 10,所以就认为6是数字24的“数根”;

而对于数字 39 , 将39的各个位上的数字“分离”,分别得到数字 3 和 9,而3+9=12,且12>10;

所以依据规则再对 12 进行相应的运算,最后得到数字3,而3<10,所以就认为3是数字39的“数根”。

通过运算可以发现任何一个数的“数根”都是一个取值范围在 1 ~ 9之间的正整数,

且任何一个正整数都只有唯一的一个“数根”与其相对应。

题目要求数字 n^n 的“数根”

解题思路:

九余数定理

一个数对九取余后的结果称为九余数。

一个数的各位数字之和想加后得到的<10的数字称为这个数的九余数(如果相加结果大于9,则继续各位相加)

代码如下:
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
char a[1010];
int i,j,s,l;
while(~scanf("%s",&a)&&a[0]!='0')
{
l=strlen(a);
s=0;
for(i=0;i<l;i++)
{
s=s+a[i]-'0';
}
s=s%9;
if(s==0)
s=9;
printf("%d\n",s);
}
return 0;
}

一个数对九取余,得到的数称之为九余数;
一个数的九余数等于它的各个数位上的数之和的九余数!

HDOJ 1013题Digital Roots 大数,9余数定理的更多相关文章

  1. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  2. Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  3. HDU-1163 Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. HDU——1163Eddy's digital Roots(九余数定理+同余定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  5. hdu 1163 Eddy's digital Roots 【九余数定理】

    http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...

  6. 1013:Digital Roots

    注意:大数要用字符串表示! sprintf:字符串格式化命令 主要功能:将格式化的数据写入某个字符串缓冲区 头文件:<stdio.h> 原型 int sprintf( char *buff ...

  7. HDU 1013 Digital Roots(字符串,大数,九余数定理)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 1013 Digital Roots【字符串,水】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. HDU 1013 Digital Roots(to_string的具体运用)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. js 配置基础启动文件

    页面启动文件boot.js,获取存放该文件的路径,放置通用的css,js代码,方便html页面调用. __CreateJSPath = function (js) { var scripts = do ...

  2. 使用Preference保存设置

    http://blog.csdn.net/barryhappy/article/details/7381544 Android中有四种持久化数据的方法:SQLite数据库.文件存储.Preferenc ...

  3. 对于百川SDK签名验证的问题

    SDK是要在wantu.taobao.com生成的.而生成这个SDK其实是要上传一个apk,而这个上传其实就是取他的签名而已.验证就是那张yw222那张图片.重点是你上传的apk的签名是不是跟你的生成 ...

  4. c语言学习之基础知识点介绍(六):if和switch结构

    本节主要说c语言中的分支结构. c语言中分支结构有两大类:一种是if,一种是switch. 一.if结构 //if结构,语法: //第一种: if(表达式){ //语句块 } //第二种: if(表达 ...

  5. OC加强-day02

    #program mark - 01 @class关键字 [掌握] 1.当两个头文件互相引用的时候,如果双方都是用#import来引入对方的头文件,就会造成死循环,编译不通过 解决方案:其中一边不要使 ...

  6. JS控制文字一个一个出现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Codevs 1140 Jam的计数法 2006年NOIP全国联赛普及组

    1140 Jam的计数法 2006年NOIP全国联赛普及组 传送门 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Jam是个喜欢标 ...

  8. gpfdist工具的初级使用

    gpfdist工具的使用主要两步: 第一步:打开gpfdist服务: gpfdist -d /home/admin -p -l /tmp/gpfdist.log & 参数解释: -d 数据文件 ...

  9. Oracel用rownum实现真分页

    因为oracle的rownum是一个伪列,使用的时候如果要用必须查询出来显示的标记例如本sql中标记为 num. 值得一提的是最内层的这个查询sql:“select a.集团规范编码...”本身有一个 ...

  10. 让IE8兼容问题,参考文档bootstrap

    问题:制作的页面基本没啥问题,只有IE8不好使 参考文档:bootstrap官网 方案一 方案二