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.



The Eddy's easy problem is that : give you the n,want you to find the n^n's digital Roots.

Input

The input file will contain a list of positive integers n, one per line. The end of the input will be indicated by an integer value of zero. Notice:For each integer in the input n(n<10000).

Output

Output n^n's digital root on a separate line of the output.

Sample Input

2
4
0

Sample Output

4
4
#include<stdio.h>
#include<string.h>
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int s=1;
for(int i=0;i<n;i++)
{
s=s*n%9; //事实上不难发现对9取余更简便。不解释为什么,仅仅能说这是一种规律 }
if(s==0)
printf("9\n");
else
printf("%d\n",s);<pre name="code" class="cpp">

}return 0;}

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int sum_dig(int n)
{
int m,sum=0;
while(n)
{
m=n%10;
sum+=m;
n/=10;
}
return sum;
}
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int s=1;
for(int i=0;i<n;i++)
{
s=n*sum_dig(s);
}
while(s>9)
{
s=sum_dig(s);
}
printf("%d\n",s);
}
return 0;
}

HDoj-1163- Digital Roots的更多相关文章

  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. HDU 1163 Eddy's digital Roots

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

  3. Digital Roots 1013

    Digital Roots 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:456            测试通过:162 描述 T ...

  4. Eddy's digital Roots

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

  5. Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏

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

  6. ACM——Digital Roots

    http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间 ...

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

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

  8. HDU1163 Eddy&#39;s digital Roots【九剩余定理】

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

  9. HDU 1013 Digital Roots(字符串)

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  10. HDU 1013.Digital Roots【模拟或数论】【8月16】

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

随机推荐

  1. LuoguP3356 火星探险问题(费用流)

    题目描述 火星探险队的登陆舱将在火星表面着陆,登陆舱内有多部障碍物探测车.登陆舱着陆后,探测车将离开登陆舱向先期到达的传送器方向移动.探测车在移动中还必须采集岩石标本.每一块岩石标本由最先遇到它的探测 ...

  2. android:giavity和layout_gravity的差别

    android:gravity: 是对该view中内容的限定.比方一个button 上面的text. 你能够设置该text 相对于view的靠左,靠右等位置. android:layout_gravi ...

  3. mac下的词典翻译快捷键

    mac下的词典翻译快捷键:cmd+ctl+d;很方便

  4. BZOJ3697: 采药人的路径(点分治)

    Description 采药人的药田是一个树状结构,每条路径上都种植着同种药材.采药人以自己对药材独到的见解,对每种药材进行了分类.大致分为两类,一种是阴性的,一种是阳性的.采药人每天都要进行采药活动 ...

  5. Zabbix 监控搭建

    Zabbix官网地址:https://www.zabbix.com/download 1.服务端 1.操作前安装好Mysql数据库 配置yum源,安装部署Zabbix rpm -i http://re ...

  6. Android DiskLruCache全然解析,硬盘缓存的最佳方案

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/28863651 概述 记得在非常早之前.我有写过一篇文章Android高效载入大图. ...

  7. LinearLayout-layout_gravity 属性没有效果分析

    今天在一个布局文件中,遇到了一个问题,先看代码 <LinearLayout android:layout_width="match_parent" android:layou ...

  8. 妙味css3课程---1-1、css中自定义属性可以用属性选择器么

    妙味css3课程---1-1.css中自定义属性可以用属性选择器么 一.总结 一句话总结:可以的. 1.如何实现用属性选择器实现a标签根据href里面含有的字段选择背景图片? p a[href*=te ...

  9. HTML基础第四讲---图像

    转自:https://blog.csdn.net/likaier/article/details/326735 图像,也就是images,在html语法中用img来表示,其基本的语法是:   < ...

  10. 4.auto详解

    #include <iostream> using namespace std; template <calss T1,class T2> auto add(T1 t1, T2 ...