hdu1163eddy's digits Roots
来源:互联网 发布:python phantomjs 编辑:程序博客网 时间:2024/06/06 06:13
Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6196 Accepted Submission(s): 3416
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.
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
240
Sample Output
44
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define mod 999999999using namespace std;int main (){ int t; int n; while(cin>>n&&n) { int i,s=1; for(i=1; i<=n; i++) { s=s*n%9; } if(s) cout<<s<<endl; else cout<<9<<endl; } return 0;}
继续快速幂,取余9
不知道为什么过不了这个
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define mod 999999999using namespace std;int PowerMod(int a, int b, int c){ int ans = 1; a = a % c; while(b>0) { if(b % 2== 1) ans = (ans * a) % c; b = b/2; a = (a * a) % c; } return ans;}int main(){ int n; while(scanf("%d",&n)!=EOF&&n) { int s=PowerMod(n,n,9); cout<<s<<endl; } return 0;}
Author
0 0
- hdu1163eddy's digits Roots
- hdu1163Eddy's digital Roots
- hdu1163Eddy's digital Roots水题
- hdu1163Eddy's digital Roots(九余数定理)
- hdu1163Eddy's digital Roots(九余数定理+同余定理)
- Eddy's digital Roots
- Eddy's digital Roots
- Eddy's digital Roots
- Eddy's digital Roots
- Eddy's digital Roots
- HDU1163 Eddy's digital Roots
- HDU1163:Eddy's digital Roots
- hdu1163-Eddy's digital Roots
- HDOJ Eddy's digital Roots
- HDU Eddy's digital Roots
- 1163:Eddy's digital Roots
- hdu1163 Eddy's digital Roots
- HDU1163 Eddy's digital Roots
- DAY16_openssl静态库使用
- java的编程基础(1)
- Jmeter 代理服务器录制脚本
- iOS动画进阶 - 实现类似美颜相机的相机启动动画
- solrJ使用基础
- hdu1163eddy's digits Roots
- 害怕遗忘,所以记录
- Android长连接心跳机制
- jquery获得select option的值 和对select option的操作
- iOS 25个性能优化/内存优化常用方法
- 2016 Multi-University Training Contest 9题解报告
- 数据库中自然连接、外连接、内连接的区别
- 网易笔试 编程
- MPAndroidChart常见设置属性(一)——应用层