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 ...
随机推荐
- CSS 将按钮转成超链接样式
一.将按钮转成超链接样式 .GoStyle { color: #0c5fc4; background-color: #FFFFFF; ...
- 【android-cocos2d-X2.2 环境配置】在Mac下搭建Cocos2d-X-android开发环境!
仅用于cocos2d-X2.2--cocos2d-X3.4 原文地址:http://blog.csdn.net/dingkun520wy/article/details/17097593 (1)下载 ...
- Create CSS3 Buttons Compatible with All Browsers
Create CSS3 Buttons Compatible with All Browsers http://www.ourtuts.com/create-css3-buttons-compatib ...
- linux grep、find 命令详解
grep1.作用grep命令可以指定文件中搜索特定的内容,并将含有这些内容的行标准输出.grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权 ...
- s3c2440之cache
cache高速缓冲存储器注意与块设备页高速缓存进行区别,一个是硬件的实现一个是软件的实现,块设备页高速缓存. s3c2440/s3c2410里面主要有一个arm920t的核,但同时包含几个协处理器,协 ...
- bnuoj 4225 杨辉三角形(规律)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4225 [题意]: 给定任意杨辉三角的行数n,请输出杨辉三角中前n行中总共有多少偶数. [题解]: 找 ...
- PD code与name联动(取消)设置
在powerdesign中,code与name老是联动,修改了name中的数据,code随之修改,影响效率,设置Tools-General Options-Dialog 中的Name to Code ...
- hibernate.cfg.xml配置(Oracle+c3p0)
说明:数据库:Oracle10g:连接池:c3p0 结构: 一.配置hibernate.cfg.xml <?xml version="1.0" encoding=" ...
- uva 10739
dp 只有三个操作 当str[i] != str[j] 时 dp(i, j) = min(dp(i+1, j), dp(i+1, j-1), dp(i, j-1)) #include <ios ...
- ural 1069
题意:删除一棵树上的叶子 每删除一片叶子就写下连着该片叶子的节点 让你还原一棵树 记录每个节点连着的叶子数 0表示此时这个节点就是叶子 -1表示这个节点已经删除 删除的只能是0 就是说是叶子 暴 ...