HDU1163 - Eddy's digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163
九余数:一个数除于9所得到的余数,即模9得到的值
求九余数:
求出一个数的各位数字之和,如果是两位数以上,则再求各位数字之和,直到只有一位数时结束。
如果求出的和是9,则九余数为0;如果是其他数,则这个数为九余数。
解题思路:快速幂+九余数
先求出九余数,如果九余数为0,则ans=9;如果是其他数,则ans=九余数。
#include <iostream>
using namespace std;
//一个数对九取余,得到的数称之为九余数
int quickerpower(int a, int b, int mod) {
int c = ;
while (b) {
if (b & ) c = c*a % mod;
b >>= ;
a = a*a % mod;
}
return c;
}
int main() {
int n, jiuyu, ans;
while (cin >> n, n) {
jiuyu = quickerpower(n, n, );
ans = jiuyu?jiuyu:;
//如果九余数为0,则ans=9;如果是其他数,则ans=九余数。
cout << ans << endl;
}
return ;
}
HDU1163 - 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
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( ...
- 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(模)
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整除:如果一个数各个数位上的数字 ...
- Hdu1163 Eddy's digitai Roots(九余数定理)
题目大意: 给定一个正整数,根据一定的规则求出该数的“数根”,其规则如下: 例如给定 数字 24,将24的各个位上的数字“分离”,分别得到数字 2 和 4,而2+4=6: 因为 6 < 10,所 ...
随机推荐
- Go语言标准库之net/http
Go语言内置的net/http包十分的优秀,提供了HTTP客户端和服务端的实现. net/http介绍 Go语言内置的net/http包提供了HTTP客户端和服务端的实现. HTTP协议 超文本传输协 ...
- WeChall_Training: PHP LFI (Exploit, PHP, Training)
Your mission is to exploit this code, which has obviously an LFI vulnerability: GeSHi`ed PHP code 1 ...
- Educational Codeforces Round 39 Editorial B(Euclid算法,连续-=与%=的效率)
You have two variables a and b. Consider the following sequence of actions performed with these vari ...
- Coroutine 预激装饰器
预激装饰器 讨论如何终止协程之前,我们要先谈谈如何启动协程.使用协程之前必须预激,可是这一 步容易忘记.为了避免忘记,可以在协程上使用一个特殊的装饰器.接下来介绍这样一个 装饰器. 预激协程的装饰器, ...
- Generator - Python 生成器
Generator, python 生成器, 先熟悉一下儿相关定义, generator function 生成器函数, 生成器函数是一个在定义体中存有 'yield' 关键字的函数. 当生成器函数被 ...
- Class Literal(Java)
前言 上一节我们讨论过通过关键字synchronized实现线程同步,同时最主要了解到在Java中className.class所代表的具体含义,在博客写完后,感觉还是有点迷糊,然后再次深入了解后,原 ...
- js—求数组中的最大最小值
参考链接:https://www.w3cplus.com/javascript/calculate-the-max-min-value-from-an-array.html Math.min.appl ...
- printf函数中*修饰符的作用,如:%*d
在printf函数中,我们可以用数字修饰来控制打印的字段宽度和精度,如下(为强调视觉效果,均填充0): #include <stdio.h> int main() { ; float f= ...
- linux中vim常用操作
三种模式 # 命令模式 vim 文件名 # 插入模式 按a/i/o 进行插入模式 按esc 重新进入命令模式 # 编辑模式 按:(冒号)进入编辑模式 插入命令 命令 作用 a 在光标所在字符后插入 A ...
- springBoot2.x启动项目报java.sql.SQLNonTransientConnectionException
将项目从springBoot1.x升级到springBoot2.x,启动报错: java.sql.SQLNonTransientConnectionException: Cannot load con ...