九余数定理

一个数对九取余后的结果称为九余数。

一个数的各位数字之和想加后得到的<10的数字称为这个数的九余数(如果相加结果大于9,则继续各位相加)

Digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 87400    Accepted Submission(s): 27256

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
Source
Greater New York 2000
#include<stdio.h>
#include<string.h>
int main()
{  char  num[1000];  int len,sum,i;  while(scanf("%s",&num)!=EOF)//这里为什么要字符串输入呢?原因是因为有一个测试数据很大,int类型肯定过不了,所以在这坑点我wa好几次{  len=strlen(num);  if(len==1 && num[0]=='0') return 0;  for(sum=0,i=0;i<len;i++)  {  sum=sum+num[i]-'0';  }  printf("%d\n",sum%9?sum%9:9);  }  return 0;
}

九余定理(hdu1013)相关推荐

  1. Codeforces数学1600----day1[同余定理,树状数组+两次二分,,组合计数]

    1.C. Kuroni and Impossible Calculation **知识点:同余定理 ** #include <iostream> #include <cstdio&g ...

  2. CSDN 厦门大学线下编程比赛第一题:求和(同余定理)

    题目意思: 给定a和n,计算a+aa+aaa+aaaa+...+a...a(n个a) 的和. 输入描写叙述:測试数据有多组,以文件结尾.每行输入a,n(1<=a,n<=1000000). ...

  3. 十二届 - CSU 1803 :2016(同余定理)

    题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Knowledge Point: 同余定理:两个整数a.b,若它们除以整数m所 ...

  4. Light oj 1214-Large Division (同余定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我 ...

  5. 同余定理在算法求解中的应用

    1. 同余定理 (a−b)modK=0⇓(amodK)=(bmodK) (a-b)\mod K=0\\ \Downarrow\\ \left(a\mod K\right) = \left(b\mod ...

  6. Divisible [数学]同余定理

    给定一个很大的整数,我想知道它能否被9整除. 输入 有t组测试数据,每组数据给定一个整数N不存在前导0.(1 <= t <= 20,1 <= N <= 10^200). 输出 ...

  7. 同余定理+前缀和解题技巧

    相关题目 和可被 K 整除的子数组 连续的子数组和 Delete Sublist to Make Sum Divisible By K 思路 前缀和就不单独说了,同余定理贴一个百度百科 同余定理 数论 ...

  8. 同余定理在计算机科学的应用,同余定理在小学数学竞赛中的应用

    肖丽 [摘要]本研究基于高观点视角,例析同余定理在小学数学竞赛中的应用,探讨运用其解决小学奥数问题的优越性. [关键词]小学数学竞赛 同余定理 应用 [中图分类号]G623.5[文献标识码]A [文章 ...

  9. 定理在数学中的简写形式_数学最奇葩的九个定理是什么

    数学最奇葩的九个定理是什么2018-10-04 10:55:31文/丁雪竹 有很多的同学是非常想知道,数学最奇葩的九个定理是什么,小编整理了相关信息,希望会对大家都有所帮助! 数学中最奇葩的定理是什么 ...

最新文章

  1. 如何远程重启和关闭系统
  2. JavaScript的特殊函数
  3. 八城联动丨神策 2020 数据驱动用户大会「成都站」邀您面基!
  4. 【问题】将数据块存储大小设置为128M,HDFS客户端写文件时,当写入一个100M大小的文件,实际占用存储空间为多大?
  5. 用XInput库使用xbox360手柄
  6. Notepad++ 6.0 发布,优化了大文件加载性能
  7. 卸载 windows_Windows 10可能很快会自动卸载有问题的Windows更新
  8. 军事医学研究院应晓敏组招聘博士后
  9. 第八章 数据结构与算法
  10. Unity 引擎 14 年!开发者除了游戏还可以用它来做什么?
  11. sed,awk,grep学习笔记
  12. 立即执行函数与Function
  13. 给linux用户的11个高级MySQL数据库面试问题和答案
  14. Swift:分别使用SwiftyJSON、ObjectMapper、HandyJSON处理JSON
  15. kali系统怎么ssh远程连接
  16. 高德地图通过经纬度获取位置信息
  17. linux无线网卡模拟ap,TP-Link无线网卡怎么设置虚拟AP
  18. 有权图的单源最短路径
  19. PYTHON用时变马尔可夫区制转换(MARKOV REGIME SWITCHING)自回归模型分析经济时间序列...
  20. iOS·NSObject的两种含义:类与协议

热门文章

  1. [MVC]Controller
  2. Nginx打开目录浏览功能(autoindex)以及常见问题解决方案
  3. 系统登录界面的验证码
  4. 关于IE记录Cookie的问题
  5. 求两个数集的并集C++代码实现
  6. tensorflow中tf.random_normal和tf.truncated_normal的区别
  7. Linux服务器和客户端之间的数据同步(备份)
  8. DLL动态链接库的工作原理
  9. 云炬Android开发笔记 12基于WebView的混合App框架设计(包含浏览器与原生请求Cookie的处理)
  10. Coursera吴恩达《神经网络与深度学习》课程笔记(5)-- 深层神经网络