HD1013Digital Roots
发布日期:2021-08-14 08:22:10 浏览次数:5 分类:技术文章

本文共 1427 字,大约阅读时间需要 4 分钟。

Problem Description

The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

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

The 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

For each integer in the input, output its digital root on a separate line of the output.

Sample Input

24 39 0

Sample Output

6 3

这题来自NewYork的题,其实一道数论题,有个小技巧,不过还是要用大数转换为字符串的方法,把每个数字相加,还是会很大.但这时可以用int了,接下来要用点数学知识:

/*

说明1.各位数字相加得到数x,这个x等于原来的数除以9的余数(原数为9的倍数除外)
    2.若原数为9的倍数,最后结果就是9;
   3.一个数字除以9的余数等于该数各数字之和除以9的余数。(这点为大数运算提供了极大的方便!)
*/

#include
#include
using namespace std;int main(){ int sum,i,x; char s[1010]; while(cin>>s && s[0]!='0') { sum = 0; for(i=0;i

转载于:https://www.cnblogs.com/LZYY/p/3306535.html

转载地址:https://blog.csdn.net/weixin_30715523/article/details/96258488 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:第十篇 requests模块
下一篇:SNMP扫描

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年03月01日 06时33分22秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

MongoDB-1-基础介绍 2019-04-20
vscode 不能使用中文输入法_vscode中vim插件设置 2019-04-21
php sequelize,egg.js整合数据库ORM框架Sequelize 2019-04-21
php+跑buth,php 中函数获取可变参数的方法, 这个语法有点像 golang 语言中的 2019-04-21
oracle报错00020,oracle启动 ORA-00020: maximum number of processes (%s) exceeded错误 2019-04-21
chmod 赋权所有_chmod 权限 命令详细用法 2019-04-21
html代码翻译_[译]您知道 HTML 的键盘标签吗? 2019-04-21
html抽奖代码_JavaScript高手之路:封装抽奖效果 2019-04-21
hadoop 3.3 一直停留在running wordcount_蛋价持续下跌,今日跌破3.3元大关!深秋季节价格还能反弹吗?... 2019-04-21
的流程图做完后如何保存_2019超火的半永久眉是哪款?做完后我们如何护理?... 2019-04-21
去除logo 高德地图api_深圳品牌logo升级如何保持原型的同时更具创新? 2019-04-21
二重积分转换成极坐标_二重积分转换极坐标r的范围如何确定? 2019-04-21
python中倒背如流_八字基础知识--倒背如流篇 2019-04-21
以太坊地址和公钥_以太坊地址是什么 2019-04-21
linux查看wifi信号命令_linux – 获取WIFI信号强度 – 寻求最佳方式(IOCTL,iwlist(iw)等)... 2019-04-21
npm 不重启 全局安装后_解决修复npm安装全局模块权限的问题 2019-04-21
vs格式化json 不生效_vs code 格式化 json 配置 2019-04-21
go 字符串反序列化成对象数组_Fastjson 1.2.24反序列化漏洞深度分析 2019-04-21
onmessage websocket 收不到信息_WebSocket断开重连解决方案,心跳重连实践 2019-04-21
hibernate mysql 缓存_hibernate和mysql的缓存问题,没辙了! 2019-04-21