Eddy's digital Roots
来源:互联网 发布:怎么做网络推广赚钱 编辑:程序博客网 时间:2024/04/30 20:48
Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4939 Accepted Submission(s): 2765
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.
240
44
JGShining | We have carefully selected several similar problems for you: 1164 1157 1194 1141 1178
分析:本题有两个重要的考点,一是九余数定理,二是快速幂取余。
九余数定理:1.一个数对九取余,得到的数称之为九余数;
2.一个数的九余数等于它的各个数位上的数之和的九余数!
代码一(九余数+快速幂):
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int fastmod(int a,int b,int k)
{
int i,j,ans=1;
a=a%k;
while(b)
{
if(b%2==1)
ans=ans*a%k;
b/=2;
a=a*a%k;
}
return ans;
}
int main()
{
int n,i;
int m;
while(scanf("%d",&n)!=EOF&&n)
{
m=1;
m=fastmod(n,n,9);
if(m)
printf("%d\n",m);
else
printf("9\n");
}
return 0;
}
代码2(九余数):
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int n,i;
int m;
while(scanf("%d",&n)!=EOF&&n)
{
m=n;
for(i=2;i<=n;i++)
{
m=(m*n)%9;
}
if(m)
printf("%d\n",m);
else
printf("9\n");
}
return 0;
}
代码3(规律):
include<stdio.h>int main(){int n;char s[20]="149429719159479789";while(~scanf("%d",&n),n)printf("%c\n",s[(n-1)%18]);return 0;}
- 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
- HDU1163 Eddy's digital Roots
- hdu1163 Eddy's digital Roots
- HDOJ1163 Eddy's digital Roots
- hdu 1163 Eddy's digital Roots
- 杭电1163 Eddy's digital Roots
- 通信系统中为什么要进行调制和解调?调制的分类方法有哪些?
- ZOJ 3861 Valid Pattern Lock
- sdfsd
- g++出现No such file or directory问题
- 冒泡排序的C++实现
- Eddy's digital Roots
- RFC3581——SIP中的rport机制
- [leetcode]Rotate Array
- 【数据结构与算法分析(一)】排序
- #290 (div.2) C. Fox And Names
- hdu 5203 Rikka with wood sticks
- 今天继续学习锋利的JQuery,第三章后半段
- Shell编程入门总结(正则表达式篇)
- ctags for systemverilog(vim用)