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 ...
随机推荐
- windows10系统window键失灵,没有反应
今天键盘的的Window键(win键)按了没反应,某度一圈全是它的垃圾营销号文章,没卵用..最后在微软官方社区支持找到解决方案.也建议大家遇到系统问题到微软社区去寻求帮助,毕竟人家是专业. 解决办法 ...
- 03011_预处理对象executeUpdate方法(实现数据库的增、删、改)
1.概述 (1)通过预处理对象的executeUpdate方法,完成记录的insert\update\delete语句的执行: (2)操作格式统一如下: ①注册驱动: ②获取连接: ③获取预处理对象: ...
- 玩转阿里云server——安装WebserverTomcat7
1. 以root用户身份登录阿里云server 2. 使用apt-get install安装Tomcat7 sudo apt-get install tomcat7 3.安装后.Tomcat在启动时报 ...
- js--27门面模式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- [BZOJ1672][Usaco2005 Dec]Cleaning Shifts 清理牛棚 线段树优化DP
链接 题意:给你一些区间,每个区间都有一个花费,求覆盖区间 \([S,T]\) 的最小花费 题解 先将区间排序 设 \(f[i]\) 表示决策到第 \(i\) 个区间,覆盖满 \(S\dots R[i ...
- sqlserver存储过程实现多表分页
if @PageIndex = 1 begin if @strWhere != ’’ set @strSQL = ’select top ’ + str(@PageSize) +’ ’+@strGet ...
- 项目列表dl、dt、dd使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- NPOI根据列索引获取列名
public static string ConvertColumnIndexToColumnName(int index) { index = index + ; ; ]; ; ) { int mo ...
- 初学WCF需要注意的地方
1.WCF的元数据发布有两种方式: a.HTTP-GET方式发布数据:让客户端使用HTTP-GET方式来获取数据是比较常见的方式.所谓HTTP—GET方式,是指当客户端发送一个HTTP-GET请求时, ...
- android:一个Open键引发的问题!!
1.问题简单介绍 首先描写叙述一下问题.当我们安装完APP的时候,界面会显示两个button,一个完毕键,一个Open键,点击Open键之后.进入应用.此时.我们点击HOME键.程序将会后台.然后再点 ...