Eddy's digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5928    Accepted Submission(s): 3270

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
 
Author
eddy
思路:求n^n对9取模,特判0的情况;
 对于那个定理的证明;
设那个数为abcd;这个数=1000*a+100*b+10*c+d;
        a+b+c+d=这个数-9999a-99b-99c;
        由于9999a-99b-9c被九整除;得证;
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
int quickpow(int a,int b,int c)
{
int ans=;
while(b)
{
if(b&)
{
ans*=a;
ans%=c;
}
b>>=;
a*=a;
a%=c;
}
return ans==?:ans;
}
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
if(!x)break;
printf("%d\n",quickpow(x,x,));
}
return ;
}
  

hdu 1163 九余数定理的更多相关文章

  1. hdu 1163 Eddy's digital Roots 【九余数定理】

    http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...

  2. HDOJ 1163 Eddy's digital Roots 九余数定理+简单数论

    我在网上看了一些大牛的题解,有些知识点不是太清楚, 因此再次整理了一下. 转载链接: http://blog.csdn.net/iamskying/article/details/4738838 ht ...

  3. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  4. HDU1013,1163 ,2035九余数定理 快速幂取模

    1.HDU1013求一个positive integer的digital root,即不停的求数位和,直到数位和为一位数即为数根. 一开始,以为integer嘛,指整型就行吧= =(too young ...

  5. HDU——1013Digital Roots(九余数定理)

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

  6. hdu-1163(九余数定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163 思路: 九余数定理:一个数对九取余的结果叫做九余数, 一个数的各个位数相加的得到的小于10的数也 ...

  7. HDU 1163 Eddy's digital Roots(模)

    HDU 1163 题意简单,求n^n的(1)各数位的和,一旦和大于9,和再重复步骤(1),直到和小于10. //方法一:就是求模9的余数嘛! (228) leizh007 2012-03-26 21: ...

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

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

  9. HDU1163【九余数定理】【水题】

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

随机推荐

  1. MUI极简的JS函数

    模块:utils http://dev.dcloud.net.cn/mui/util/#event mui.init(); mui框架将很多功能配置都集中在mui.init方法中,要使用某项功能,只需 ...

  2. CEIL与FLOOR

    SQL> SELECT 666.88,CEIL(666.88),FLOOR(666.88) FROM dual;    666.88 CEIL(666.88) FLOOR(666.88)---- ...

  3. json包的不同导致结果不同

    json包的不同导致结果不同 引入如下json jar包 import org.json.JSONArray; 2 import org.json.JSONObject; 代码: JSONObject ...

  4. mongodb拆库分表脚本

    脚本功能: 1. 将指定的报告文件按照指定的字段.切库切表策略切分 2. 将切分后的文件并发导入到对应的Mongodb中 3. 生成日志文件和done标识文件 使用手册: -h    打印帮助信息,并 ...

  5. 170605、防止sql注入(二)

    java filter防止sql注入攻击 原理,过滤所有请求中含有非法的字符,例如:, & <  select delete 等关键字,黑客可以利用这些字符进行注入攻击,原理是后台实现使 ...

  6. 南京网络赛I-Skr【回文树模板】

    19.32% 1000ms 256000K A number is skr, if and only if it's unchanged after being reversed. For examp ...

  7. Mac下通过远程桌面向Windows发送Ctrl+Alt+Delete

    今天在Mac中通过远程桌面给Windows安装Git Extensions,在安装程序自动关闭资源管理器时,Windows无响应,桌面显示黑屏.于是,想通过Ctrl+Alt+Delete快捷键调出对话 ...

  8. Prometheus 操作符

    操作符 二元操作符 Prometheus的查询语言支持基本的逻辑运算和算术运算.对于两个瞬时向量, 匹配行为可以被改变. 算术二元运算符 在Prometheus系统中支持下面的二元算术操作符: + 加 ...

  9. Oracle性能优化之Oracle里的统计信息

    一.什么是统计信息 oracle数据库里的统计信息是如下的一组数据:他们存储在数据字典里,且从多个维度描述了oracle数据库数据对象的详细信息. oracle数据库里的统计信息主要分为以下6种情况: ...

  10. JavaScript原型链的理解

    JavaScript中的每一个对象都有prototype属性,我们称之为原型,而原型的值也是一个对象,因此它有自己的原型,这样就串联起来形成了一条原型链.原型链的链头是object,它的prototy ...