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. 解决pip install 安装慢问题

    使用豆瓣源 比如安装pyspark pip install -i https://pypi.douban.com/simple/ pyspark 速度就比用pip install快N倍 关注公众号:

  2. Android数据存储之SQLite 数据库学习

    Android提供了五种存取数据的方式 (1)SharedPreference,存放较少的五种类型的数据,只能在同一个包内使用,生成XML的格式存放在设备中 (2) SQLite数据库,存放各种数据, ...

  3. LightBGM之Dataset

    最近使用了LightBGM的Dataset,记录一下: 1.说明: classlightgbm.Dataset(data, label=None, reference=None, weight=Non ...

  4. RGBA HSB opengl光照模型

    RGBA HSB   HSV颜色模型对应于画家的配色的方法.画家用改变色浓和色深的方法来从某种纯色获得不同色调的颜色.其做法是:在一种纯色中加入白色以改变色浓,加入黑色以改变色深,同时加入不同比例的白 ...

  5. flask中Flask()和Blueprint() flask中的g、add_url_rule、send_from_directory、static_url_path、static_folder的用法

    1.Blueprint()在蓝本注册函数register_blueprint()中,第一个参数为所注册的蓝本名称.当我们在应用对象上注册一个蓝图时,需要指定一个url_prefix关键字 参数(这个参 ...

  6. Python开发【模块】:邮件

    邮件 1.简单发送 settings.py配置: import os import sys,string from bin.start import BASE_DIR # 日志存放地址 RUN_LOG ...

  7. pandas 从txt读取DataFrame&DataFrame格式化保存到txt

    前提 首先保证你txt里的文本内容是有规律可循的(例如,列与列之间通过“\t”.“,”等指定的可识别分隔符分隔): 例如我需要读取的数据,(\t)分隔: (此文件内容是直接以DataFrame格式化写 ...

  8. vue知识总汇

    学前预备知识 ECMAScript简介和ES6的新增语法 Nodejs基础 webpack的介绍 babel简介 vue基础 vue基础

  9. jQuery-添加、移出事件

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  10. linux更改文件或目录的属主和属组

    chown  1.效用  更改一个或者多个文件或者目录的属主以及属组,使用职权范围是超等用户  2.格局  chown [选项] 用户或者组 文件  3.首要参量  --dereference:受影响 ...