1784:Digital Roots

2024-08-26 09:38
文章标签 1784 digital roots

本文主要是介绍1784:Digital Roots,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目描述

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.

输入格式

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.

输出

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

样例输入

24
39
0

样例输出

6
3

#include<stdio.h>
int fan(int num)
{
int d=num;
while(d>=10)
{ 
d=0;
while(num)
{
d+=num%10;
num=num/10;
}
num=d;
}
return d;
}   
int main()
{
char str[1000];
int n,i;
while(scanf("%s",str)!=EOF && str[0]!='0')
{
n=i=0;
while(str[i])
{
n+=str[i]-'0';
i++;
}
printf("%d\n",fan(n));
}
return 0;
}


 

这篇关于1784:Digital Roots的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1108195

相关文章

语音信号处理2:数字滤波器 Digital Filters

参考: The Scientist and Engineer’s Guide to Digital Signal Processing Multimedia Signal Processing: Theory and Applications in Speech, Music and Communications Classification 欲知细节,先识大体,看看数字滤波器都有哪些种类吧

error:0308010C:digital envelope routines::unsupported【超详细图解】

目录 一、报错信息 二、分析原因 三、解决方案 一、报错信息 二、分析原因 node.js 18 不兼容oppsll,node.js v17以上版本中最近发布的OpenSSL3.0, 而OpenSSL3.0对允许算法和密钥大小增加了严格的限制 三、解决方案 方案1:打开终端,直接输入 Linux & Mac OS: export NODE_OPTIONS=

[POJ 1284] Primitive Roots (数论,原根)

POJ - 1284 题意是,求一个质数的原根 原根的定义是,对于正整数 aimodp(i=[1,p−1]) a^i mod p (i=[1,p-1])得到的集合为{1,2,…,p-1},那么则称 a是 p的一个原根 对于任意正整数 p,其原根个数为 ϕ(ϕ(p)) \phi( \phi(p) ), ϕ(n) \phi(n)为欧拉函数,表示小于n且与n互质的数的个数 而质数的欧拉函数值

poj 1284 Primitive Roots(数论:欧拉函数)

我开始还以为是求最小原根呢 直接打表+快速幂取模 后来才发现是求原根的个数 结果为phi(n-1) 证明就不再赘述了,网上很多 而且感觉这种题太偏了,没有必要浪费太多时间 代码如下: #include <cmath>#include <cstdio>#include <iostream>using namespace std;int euler_phi(int n) {in

0.3 数字电视(Digital television)简介

0.3 数字电视简介 数字电视是指采集、播出、传输、接收等环节中全面采用数字信号的电视系统。现代数字电视分辨率比模拟电视更高。通常使用宽屏(宽高比为 16:9),与模拟电视的窄屏(宽高比为 4:3)形成鲜明对比。 数字电视标准 世界不同地区采用了不同的数字电视广播标准;以下是广泛使用的标准: DVB(Digital Video Broadcasting),被欧洲、非洲、亚洲和澳大利亚等约60

The first experiment about digital filter 软件滤波初体验

软件滤波初体验 选择最好玩的方波 预设波形如下: 频谱,你懂的: 如果只对低频部分进行inverse-DFT,那么: 当 for frequency = -(circle/20):(circle/20)-1 取circle/20以下的部分,低频断: nice! 如果此时放宽滤波频段至circle/8 一个高频信号就会叠加

数字取证技术(Digital Forensics Technology)实验课II

@数字取证技术(Digital Forensics Technology)实验课II 本文是我本学期的教学课题目,不包含任何博客知识分享,无关的读者可忽略; 实验练习题 (♞思考):请对工作邮件进行签名;“problem3_1.txt"里存储的是由John Doe撰写的真实的邮件,而"problem3_2.txt"里存储的是其他人恶意伪造的邮件(关键时间作了篡改);内容分别如下,请

Vue Node 编译报错:digital envelope routines::unsupported

错误内容 Error: error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:67:19)at Object.createHash (node:crypto:130:10) 错误原因 因为 nodeJs v17 版本发布了 OpenSSL3.0 对算法和秘钥大小

外汇天眼:野村证券和Laser Digital与GMO互联网集团合作发行日元和美元稳定币

野村控股和Laser Digital将与GMO互联网集团合作,在日本探索发行日元和美元稳定币。GMO互联网集团的美国子公司GMO-Z.com Trust Company, Inc. 在纽约州金融服务部的监管框架下,在以太坊、恒星币和Solana等主要区块链上发行稳定币。GMO-Z.com Trust Company 运营着一个支持数字货币安全管理的强大系统;该系统支持多个技术平台,并包括监控货币交

Digital Image Processing System(DIPS)

数字图像处理系统  Digital Image Processing System(DIPS) 早前版本: ​​​​​​​DIPS_YTPC OCR-CSDN博客