HDU 1163 Eddy's digital Roots
Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5783 Accepted Submission(s): 3180
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 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).
//计算x的y次幂(快速)
int quickpow(int x,int y)
{
int ret = ;
while(y){
if(y&)
ret *= x;
x *= x;
y >>= ;
}
return ret;
}
//计算x的y次幂对mod取模(快速)
int quickpowmod(int x,int y,int mod)
{
int ret = ;
x %= mod;
while(y){
if(y&)
ret = ret*x%mod;
x = x*x%mod;
y >>= ;
}
return ret;
}
#include <cstdio> int quickpowmod(int x,int y,int mod)
{
int ret = ;
x %= mod;
while(y){
if(y&)
ret = ret*x%mod;
x = x*x%mod;;
y >>= ;
}
return ret;
} int main()
{
int n;
while(scanf("%d",&n), n){
int ans = quickpowmod(n,n,);
printf("%d\n",ans == ? : ans);
}
return ;
}
HDU 1163 Eddy's digital Roots的更多相关文章
- HDU 1163 Eddy's digital Roots(模)
HDU 1163 题意简单,求n^n的(1)各数位的和,一旦和大于9,和再重复步骤(1),直到和小于10. //方法一:就是求模9的余数嘛! (228) leizh007 2012-03-26 21: ...
- hdu 1163 Eddy's digital Roots 【九余数定理】
http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被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 ...
- HDOJ 1163 Eddy's digital Roots 九余数定理+简单数论
我在网上看了一些大牛的题解,有些知识点不是太清楚, 因此再次整理了一下. 转载链接: http://blog.csdn.net/iamskying/article/details/4738838 ht ...
- 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 ...
- Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU1163 - Eddy's digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数:一个数除于9所得到的余数,即模9得到的值 求九余数: 求出一个数的各位数字之和,如果是两 ...
- HDU1163 Eddy's digital Roots【九剩余定理】
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
随机推荐
- oracle 导入报错 ORA-00959: tablespace 'HB' does not exist
导入oracle 时发现有几张表导入时一直报错: 报错信息:IMP-00003: ORACLE error 959 encountered ORA-00959: tablespace 'HB' d ...
- 2016 系统设计第一期 (档案一)MVC ajax 获取json数据
我在做一张表的增删改查的时候,在编辑的时候,需要获取当前选择行对应的Id,然后并且把选择行的Id的对于的数据取出来,代码如下: 列表a标签绑定: Js代码: url: '/Users/GetUserB ...
- js 人工获取年月日
var date = new Date(); var months = new Array("01", "02", "03", " ...
- sed 常见用法
sed 1. 移除空白行 sed '/^$/d' file 2. 直接在文本中进行替换 sed 's/pattern/replacement/g' -i file -i[SUFFIX], --in-p ...
- 写作技巧--Simile明喻
- NIO的Selector
参考自 Java NIO系列教程(六) Selector Java-NIO-Selector java.nio.channels.Selector NIO新功能Top 10(下) 出发点: 如何管理多 ...
- [笨木头FireFly 02]入门篇2_客户端发送请求,服务器处理请求
原地址:http://www.9miao.com/question-15-53940.html 好,经过上一篇不权威的讲解,大家已经能轻易地让客户端和服务端连接起来了. 但是,仅仅是连接了,可它们俩不 ...
- Unity3D NGUI自适应屏幕分辨率(2014/4/17更新)
原地址:http://blog.csdn.net/asd237241291/article/details/8126619 原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 本文链接地址: ...
- 为你的PHP程序选择合适的密码库(初稿)
如果本文中的术语让你感到疑惑,请先参阅密码学术语及概念一文. 密码学不是魔术.加密一个应用程序并不能保证它在袭击下的安全(特别是在你没有设置验证密文的情况下).但如果出于商业需求你要确保程序的安全,传 ...
- RASP 完爆 WAF 的5大理由!
Web 应用防火墙(WAF)已经成为常见 Web 应用普遍采用的安全防护工具,即便如此,WAF 提供的保护方案仍旧存在诸多不足,笔者认为称 WAF 为好的安全监控工具更为恰当.幸运的是,应用安全保护技 ...