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,所 ...
随机推荐
- https搭建(自签名证书)
博客搬家: https搭建(自签名证书) 上一篇博客探究了https(ssl)的原理,为了贯彻理论落实于实践的宗旨,本文将记录我搭建https的实操流程,使用Apache2+ubuntu+openss ...
- Codeforces_334_C
http://codeforces.com/problemset/problem/334/C 求不能凑整n,和最小,数量最多的数量. #include<iostream> #include ...
- Codeforces_451_B
http://codeforces.com/problemset/problem/451/B 取前后第一个不满足条件的位置,逆序,判断. #include<cstdio> #include ...
- Latent Representation Learning For Artificial Bandwidth Extension Using A Conditional Variational Auto-Encoder
博客作者:凌逆战 论文地址:https://ieeexplore.ieee.xilesou.top/abstract/document/8683611/ 地址:https://www.cnblogs. ...
- USBWebServer - 在U盘里搭一个Web服务器!
文章选自我的博客:https://blog.ljyngup.com/archives/321.html/ 本文将介绍一款可以在U盘内直接搭建Web服务器的软件 软件可以免安装直接在U盘内运行,适合外出 ...
- javascript原生js轮播图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- PHP+mysql数据库简单分页实例-sql分页
前几天冷月写了一篇博文<php基础编程-php连接mysql数据库-mysqli的简单使用>,很多小伙伴在学习后都知道了php与mysql数据库的连接,今天冷月分享一个简单的分页实例 首先 ...
- df du 文件空间管理 命令
df 可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力. du 可以查看文件及文件夹的大小. df:常用 df -h 以易读形式显示 磁盘空间 linux ...
- 单元测试-xUnit总结
xUnit总结 什么是xUnit xUnit.net是针对.NET Framework的免费,开源,以社区为中心的单元测试工具. 自动化测试的优点 可以频繁的进行测试 可以在任何时间进行测试,也可以按 ...
- Java synchronized 关键字详解
Java synchronized 关键字详解 前置技能点 进程和线程的概念 线程创建方式 线程的状态状态转换 线程安全的概念 synchronized 关键字的几种用法 修饰非静态成员方法 sync ...