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. JS错误记录 - 右侧悬浮框 - 缓冲运动

    本次练习错误总结: 1.  正确: startMove( document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop); ...

  2. DM9000C网卡驱动

    目的:通过学习,掌握如何移植.编写DM9000C网卡驱动 一.概述: DM9000是一款高度集成低功耗快速以太网处理器,该芯片集成了MAC和PHY.DM9000可以和CPU直接连接,支持8位.16位和 ...

  3. 使用pandas导出PostgreSQL 模式下的所有表数据并保存

    PostgreSQL PostgreSQL 是一个非常强大的数据库,它是一个免费的对象-关系数据库服务器(数据库管理系统).PostgreSQL支持大部分 SQL 标准, 在语句上也有很大的相似的地方 ...

  4. 电商系统Broadleaf文档翻译(六) - 主要实体main entities

    主要实体 原文标题:main entities 原文出处:http://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/d ...

  5. 兔子--百度地图所需的jar+so下载地址

    百度地图所需的jar+so下载地址:http://download.csdn.net/detail/u013425527/8265569

  6. php课程 18-60 cookie和session的最主要区别是什么

    php课程 18-60 cookie和session的最主要区别是什么 一.总结 一句话总结:存储位置不同:cookie存储在客户端:session存储在服务端. 1.cookie和session在p ...

  7. Logstash读写性能调整优化

    继续

  8. HDU 1197 Specialized Four-Digit Numbers

    Specialized Four-Digit Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  9. 【习题 7-4 UVA-818】Cutting Chains

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二进制枚举要解开哪些环. 把所有和它相关的边都删掉. 对于剩下的联通分量. 看看是不是每一个联通分量都是一条链 ->每个点的度 ...

  10. 【AIM Tech Round 4 (Div. 2) C】Sorting by Subsequences

    [链接]http://codeforces.com/contest/844/problem/C [题意] 水题,没有记录意义 [题解] 排序之后,记录每个数字原来在哪里就好. 可以形成环的. 环的个数 ...