hdu 1163
别人的代码开始自己不知道什么数论解法:
ab*ab=(a*10+b)(a*10+b)=a^2*100+2ab*10+b^2
所以the root digital=(a+b)*(a+b);
而数论中的定理:两数之积对9取余数等于两数对9的余数的乘积。 代码:
#include"stdio.h"
int main()
{
int i,n,sum;
while(scanf("%d",&n)!=EOF&&n!=0)
{
sum=1;
for(i=0;i<n;i++)
{
sum=sum*n%9;
}
if(sum==0)
printf("9\n");
else
printf("%d\n",sum);
}
return 0;
}
我的ac代码:
#include<stdio.h>
__int64 seach(__int64 u) {
__int64 sum=0;
while(u) {
sum=sum+u%10;
u/=10;
}
if(sum<10)
return sum;
return seach(sum);
}
__int64 dfs(__int64 n,__int64 index) {
if(index==1)
return n;
if(index==0)
return 1;
if(index%2==1)
return n*dfs(seach(n*n),index/2);
return dfs(seach(n*n),index/2);
}
int main() {
__int64 n,m,i,j,k;
while(scanf("%I64d",&n),n) {
printf("%I64d\n",seach(dfs(seach(n),n)));
}
return 0;
}
hdu 1163的更多相关文章
- HDU 1163 Eddy's digital Roots(模)
HDU 1163 题意简单,求n^n的(1)各数位的和,一旦和大于9,和再重复步骤(1),直到和小于10. //方法一:就是求模9的余数嘛! (228) leizh007 2012-03-26 21: ...
- hdu 1163 Eddy's digital Roots 【九余数定理】
http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...
- HDU 1163 Eddy's digital Roots
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1163 九余数定理
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- 【cl】maven新建项目
http://blog.csdn.net/sushengmiyan/article/details/40142771 使用maven创建一个helloworld 在本地硬盘创建一个文件夹作为maven ...
- C#调用C++回调函数的问题
C++的回调函数中有一个参数是,是返回一个字符串,原则如下: typedef void (*TDataEvent)(char *AData ,int ALen); 其中char ...
- Truck History --hdoj
Truck History Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
- 数组、链表、栈、队列和STL
数组 数组是一种最基本的数据结构,它是内存上的一块连续存储空间.正因如此数组的随机访问很方便.但数组也有其固有的限制,大小分配后不能改变. STL中的数组 STL中的Array是静态数组模板,就是我们 ...
- BZOJ 3992 DP+NTT+快速幂
思路: 普通的DP很好想吧 f[i][j]+=f[i-1][j*s[k]] 前i个数 mod m=j 的个数 m是质数 模数是质数 这就很有趣了 那么我们就求出来原根 所有的数都取指数 搞出 ...
- [转]C# ListView 单击标题实现排序(在转载的基础上有所完善)
using System; using System.Collections; using System.Windows.Forms; //在转载的基础上有所完善 namespace TDRFacto ...
- 3.Ventuz Designer新建项目Demo
Ventuz Designer新建项目Demo 1.打开ventuz,点Recent Projects>New Project,在弹出的界面填写具体项目信息,如下图: 图1.1 图1.2 2.在 ...
- BZOJ3573: [Hnoi2014]米特运输(树上乱搞)
Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1669 Solved: 1031[Submit][Status][Discuss] Descript ...
- P3399 丝绸之路
题目背景 张骞于公元前138年曾历尽艰险出使过西域.加强了汉朝与西域各国的友好往来.从那以后,一队队骆驼商队在这漫长的商贸大道上行进,他们越过崇山峻岭,将中国的先进技术带向中亚.西亚和欧洲,将那里的香 ...
- java exception 异常错误记录
//异常:Could not obtain transaction-synchronized Session for current thread 做定时器的时候用ApplicationContext ...