HDOJ 1013题Digital Roots 大数,9余数定理
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.
24
39
0
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余数定理的更多相关文章
- HDOJ 1163 Eddy's digital Roots(九余数定理的应用)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU-1163 Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU——1163Eddy's digital Roots(九余数定理+同余定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1163 Eddy's digital Roots 【九余数定理】
http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...
- 1013:Digital Roots
注意:大数要用字符串表示! sprintf:字符串格式化命令 主要功能:将格式化的数据写入某个字符串缓冲区 头文件:<stdio.h> 原型 int sprintf( char *buff ...
- HDU 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1013 Digital Roots【字符串,水】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
随机推荐
- .NET设计模式(9):桥接模式(Bridge Pattern)
.NET设计模式(9):桥接模式(Bridge Pattern) 桥接模式(Bridge Pattern) --.NET设计模式系列之九 年月 实现代码如下:..所谓抽象和实现沿着各自维度的变 ...
- A题笔记(6)
No. 3040 代码量好少,主要考到数学知识 唯一需要注意的是变量的类型 int -2147483648 ~ +2147483647 (4 Bytes) long 在32位机器中 int 类型 和 ...
- Synchronized vs SyncRoot
我们知道,在.net的一些集合类型中,譬如Hashtable和ArrayList,都有Synchronized静态方法和SyncRoot实例方法,他们之间有联系吗?我怎么才能用好他们呢?我们以Hash ...
- Oracle11g服务及实例
1Orcl服务说明 1) Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Service)能够让存储基础设备 ...
- boost::bind实践
第一部分源码为基础实践: /*Beyond the C++ Standard Library ( An Introduction to Boost )[CN].chm*/ /*bind的用法*/ #i ...
- printf 输出格式
printf 输出格式C中格式字符串的一般形式为: %[标志][输出最小宽度][.精度][长度]类型,其中方括号[]中的项为可选项.各项的意义介绍如下:1.类型类型字符用以表示输出数据的类型,其格式符 ...
- grub2 使用memdisk工具 启动任意iso
root@zhanghua-Inspiron-:/home/zhanghua# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda6 60G 12G 46G 21% / none ...
- 设置(TableViewController)通用框架
本文学习于传播播客.李明杰老师.感谢
- C# 仿迅雷风格选项卡
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { listView1.FullRowSelect = ...
- GCC编译器的安装
1.GCC简介 GCC(GNU Compiler Collection)是一套功能强大.性能优越的编程语言编译器,它是GNU计划的代表作品之一.GCC是Linux平台下最常用的编译器,GCC原名为GN ...