HDoj-1163- Digital Roots
Problem Description
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
Output
Sample Input
2
4
0
Sample Output
4
4
#include<stdio.h>
#include<string.h>
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int s=1;
for(int i=0;i<n;i++)
{
s=s*n%9; //事实上不难发现对9取余更简便。不解释为什么,仅仅能说这是一种规律 }
if(s==0)
printf("9\n");
else
printf("%d\n",s);<pre name="code" class="cpp">}return 0;}
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int sum_dig(int n)
{
int m,sum=0;
while(n)
{
m=n%10;
sum+=m;
n/=10;
}
return sum;
}
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int s=1;
for(int i=0;i<n;i++)
{
s=n*sum_dig(s);
}
while(s>9)
{
s=sum_dig(s);
}
printf("%d\n",s);
}
return 0;
}
HDoj-1163- Digital Roots的更多相关文章
- HDOJ 1163 Eddy's digital Roots(九余数定理的应用)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- HDU 1163 Eddy's digital Roots
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Digital Roots 1013
Digital Roots 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:456 测试通过:162 描述 T ...
- Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- ACM——Digital Roots
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间 ...
- Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU1163 Eddy's digital Roots【九剩余定理】
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1013 Digital Roots(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013.Digital Roots【模拟或数论】【8月16】
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
随机推荐
- Flask的快速入门详细笔记
Flask的框架结构对应关系及理解 1.简介 简单介绍下Flask是一个轻量级的web前端框架,不像django那样本身具备一套完整的页面体系,轻量级说明了完全可以自定义,从功能逻辑到业务处理,都可以 ...
- 【习题 8-11 UVA - 1615】Highway
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个村庄都有一个范围[li..ri] 只要在这个范围内放点都可以"支配"这个村庄. 则问题就等价于线段上有n个区 ...
- WPF通用管理框架 项目客户端基础结构介绍
介绍 首先, 粗糙的展示一下目前的结构设计理念, 因为这几天一直在忙于工作, 所以跟进有些缓慢, 整体的设计是支持多种服务模式.目前只针对MSSQL做数据库接口, ORM选型则用的是微软的EF(PS: ...
- Spring AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)(转)
1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下让你不知所措,心想着:管不得很多人都和我说AOP多难多难.当我看进去以后, ...
- 将 php 转换/编译为 EXE
将 php 转换/编译为 EXE 本文仅仅是将原文用谷歌作了翻译,原文来源于 http://stackoverflow.com 资料来源 http://stackoverflow.com/quest ...
- [LuoguP4892]GodFly的寻宝之旅 状压DP
链接 基础状压DP,预处理出sum,按照题意模拟即可 复杂度 \(O(n^22^n)\) #include<bits/stdc++.h> #define REP(i,a,b) for(in ...
- thinkphp多层volist实现多表查询
thinkphp多层volist实现多表查询 一.总结 二.截图 三.代码 1.控制器 2.视图
- [NOI2008]假面舞会(DFS)
Description 一年一度的假面舞会又开始了,栋栋也兴致勃勃的参加了今年的舞会.今年的面具都是主办方特别定制的.每个参加舞会的人都可以在入场时选择一 个自己喜欢的面具.每个面具都有一个编号,主办 ...
- Maven学习总结(14)——Maven 多模块项目如何分工?
一.开场白 使用Maven有段时间了,只能感慨真是个好东西,让我从传统模式体会到了严谨.规范.敏捷.方便的特性. 如果你懂Maven或许看过Juven翻译的<Maven权威指南>: 发个牢 ...
- 79.cgi硬盘查询个人信息
运行截图: 把cgi编码转为char*类型 //把cgi编码转为char*类型 char* change(char *str) { //分配内存 ); //x是tempstr的下标,y是str的下标 ...