HDU 1163 Eddy's digital Roots(模)
题意简单,求n^n的(1)各数位的和,一旦和大于9,和再重复步骤(1),直到和小于10.
//方法一:就是求模9的余数嘛! (228) leizh007 2012-03-26 21:03:19 (确实可行)
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,ans;
while(scanf("%d",&n),n)
{
ans=;
for(i=;i<n;i++)
{
ans=(ans%)*n;
if(ans==)
ans=;
}
ans=ans%;
if(ans==)
ans=;
printf("%d\n",ans);
}
return ;
}
//方法二:乘一次,加一次(这个也可行,这是我自己想的哦~哈哈)
#include<stdio.h>
#include<string.h>
int f(int num)
{
int ans=;
while(num)
{
ans=num%+ans;
num=num/;
}
if(ans>)
return f(ans);
return ans;
}
int main()
{
int n,i,ans,num;
while(scanf("%d",&n),n)
{
ans=f(n);
for(i=;i<n;i++)
{
num=ans*n;
ans=f(num);
}
printf("%d\n",ans);
}
return ;
}
HDU 1163 Eddy's digital Roots(模)的更多相关文章
- 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 【九余数定理】
http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数定理: 如果一个数的各个数位上的数字之和能被9整除,那么这个数能被9整除:如果一个数各个数位上的数字 ...
- HDOJ 1163 Eddy's digital Roots(九余数定理的应用)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- HDOJ 1163 Eddy's digital Roots 九余数定理+简单数论
我在网上看了一些大牛的题解,有些知识点不是太清楚, 因此再次整理了一下. 转载链接: http://blog.csdn.net/iamskying/article/details/4738838 ht ...
- HDU-1163 Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU1163 - Eddy's digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163 九余数:一个数除于9所得到的余数,即模9得到的值 求九余数: 求出一个数的各位数字之和,如果是两 ...
- HDU——1163Eddy's digital Roots(九余数定理+同余定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
随机推荐
- 与谷歌测试工程师的对话 - from Google Testing Blog
Conversation with a Test Engineer by Alan Faulner Alan Faulner谷歌的一名测试工程师,他工作在DoubleClick Bid Manager ...
- hashCode()和toString()
hashCode函数和toString函数也在Object类中,同样,所有的类都继承了这2个函数. hashCode函数用于生成哈希码,没有参数,返回值为整型 把u的值作为键存入map中,使用get方 ...
- find your present
Description In the present, and their card numbers are , , , , .so your present will be the one with ...
- NOJ1066-堆排序
堆排序 时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 414 测试通过 : 220 比 ...
- hdu 4027 Can you answer these queries?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...
- poj 1862 Stripies/优先队列
原题链接:http://poj.org/problem?id=1862 简单题,贪心+优先队列主要练习一下stl大根堆 写了几种实现方式写成类的形式还是要慢一些... 手打的heap: 1: #inc ...
- c/c++常用代码--使用libcurl下载文件
#pragma once #include <stdio.h>#include <stdlib.h> #include <curl/curl.h> #ifdef ...
- modelsim仿真错误解决办法
编译不成功可能是因为: 1.本身程序有问题. 2.没有设置顶层文件 3.modelsim 出现错误是不要只是看错误的地方,也要看前面的一部分
- sublime mac快捷键
^是control ⌥是option 打开/前往 ⌘T 前往文件 ⌘⌃P 前往项目 ⌘R 前往 method ⌘⇧P 命令提示 ⌃G 前往行 ⌘KB 开关侧栏 ⌃ ` python 控制台 ⌘⇧N 新 ...
- Android -- View
setContentView 只要你使用过Activity ...