Digital Roots:高精度
C - Digital Roots
Description
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.
Input
input file will contain a list of positive integers, one per line. The
end of the input will be indicated by an integer value of zero.
Output
Sample Input
24
39
0
Sample Output
6
3
题目描述:多组输入,输入n,把n的每一位加起来,求出新的n来,不断地加,直到n小于10.用到九余定理。
#include<iostream>
#include<string>
using namespace std;
int main() {
string s;
while (cin>>s) {
int ans = 0;
int lens = s.size();
for (int i = 0; i < lens; i++) {
ans += s[i] - '0';
}
if (ans == 0)break;
else
cout << (ans- 1) % 9 + 1 << endl; //九余定理
}
return 0;
} /*
设x是一个四位数
x=a*1000+b*100+c*10+d => x=a*999+b*99+c*9+d+a+b+c =>要求a+b+c+d 即求 (a*999+b*99+c*9+d+a+b+c)%9即可, 即求x%9
特例x==9时,,所以先-1,取余9后再+1
例如45=4+5=9
如果9%9==0 但是结果是0
*/
Digital Roots:高精度的更多相关文章
- 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 ...
- HDU 1163 Eddy's digital Roots
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- ACM——Digital Roots
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 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 ...
- 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 ...
随机推荐
- Unity Loding白屏
卡loading很多时候是由于网络原因造成的,你可以尝试断网,进入离线模式.如果使用VPN也可以先关闭使用,部分Vpn的配置也会导致该问题出现.最后可以查看一下防火墙的设置.
- CSS节选——选择器
CSS,cascading style sheet,层叠样式表,请留意层叠概念. css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:link,:active,:targ ...
- js获取当前时间并转化
1.转化为 年月日 function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var ...
- 在angular7中创建组件/自定义指令/管道
在angular7中创建组件/自定义指令/管道 组件 使用命令创建组件 创建组件的命令:ng generate component 组件名 生成的组件组成: 组件名.html .组件名.ts.组件名. ...
- 纯 js 实现上传文件支持拖拽
开发「bufpay.com 个人即时到账收款平台」 后台需要支持开发者的微信和支付宝二维码上传. <p> <button class="btn btn-primary&qu ...
- 浅析中国剩余定理(从CRT到EXCRT))
前置知识 1. a%b=d,c%b=e, 则(a+c)%b=(d+e)%b(正确性在此不加证明) 2. a%b=1,则(d\(\times\)a)%b=d%b(正确性在此不加证明) 下面先看一道题(改 ...
- bat脚本实现复制特定后缀文件到其他目录
@echo off for /r %%a in (*.txt) do copy %%a D:\1 pause 1.for /r主要用于搜索指定路径及其所有子目录中符合要求的文件(/r后如果没有指定目录 ...
- c# Reverse()的两点用法
Rervese的基本用途是:反转数组中元素的顺序,常见的两种用法如下: 1.void Array.Reverse(Array array) static void Main(string[] args ...
- js之冒泡排序与快速排序
//冒泡排序 let arr = [1, 6, 3, 7, 5, 9, 2, 8]; function sort(arr) { //升序 console.time("冒泡排序耗时" ...
- HTML5视频播放练习:鼠标经过视频播放,鼠标移除停止播放,再次经过继续播放。
随着HTML5的广泛应用,在一些网站中,经常看到有些预览的短视频预览,鼠标经过就会播放,移除就会停止播放,再次移进去就会继续播放. 自己也研究着做一个比较简单的类似的练习. 视频可以自己到包图网下载, ...