数论之数字根 杭电1013
来源:互联网 发布:世界银行预测数据 编辑:程序博客网 时间:2024/05/22 15:44
做这道题就有一种感觉,,数学真是奇妙,,在网上查了一下,才知道数字根有那么多奇妙的性质。不过,对于这道题我却是不太理解,,主要是不会证明为什么数字根就是各个位加起来对9取余,,我试着用同余证了一下,,可惜,,没证出来,,还希望高手指点。题目:
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
63
ac代码:
#include <iostream>#include <cstdio>#include <string>#include <string.h>using namespace std;int main(){ char ch[10005]; int sum=0; while(cin>>ch&&ch[0]!='0') { int len=strlen(ch); sum=0; for(int i=0;i<len;++i) { sum+=(ch[i]-'0'); } if(sum%9==0) printf("9\n"); elseprintf("%d\n",sum%9); } return 0;}
- 数论之数字根 杭电1013
- ACM之数论数字根
- HDU 1013 (数字根)
- 数字根
- 数字根
- 数字根
- hdu 1013 digital roots(数字根)
- hud 1013 求一个数的数字根
- 杭电 1164 数论
- 杭电 1017 数论
- 杭电 3833 数论
- 杭电 2879 数论
- 数字根介绍
- POJ1519数字根 问题
- 【TJOI2013】数字根
- TJOI2013_数字根
- 8数字根
- 【1402】数字根
- Bash 使用技巧大补贴
- 软件学院“SIdea”软件创意大赛
- 无法通过128扩展temp段
- Bellman-Ford算法(转自http://www.cppblog.com/infinity/archive/2008/11/11/66621.html)
- hdu 1106
- 数论之数字根 杭电1013
- 【转】注册表命令大全
- ext4 利用actioncolumn来实现增删改查
- 2011-9-20 11:47:38
- 删除数组中相同元素[等同内置函array_unique]
- 级联下拉列表
- linux 用户id 有效用户id 保存设置id
- 转如何生成不规则形状的mask,以解决对图像不规则区域设置ROI的问题
- poj 3345