HDU1163 Eddy's digital Roots【九剩余定理】

简介:

Eddy's digital Roots

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


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.

The Eddy's easy problem is that : give you the n,want you to find the n^n's digital Roots.
 

Input
The input file will contain a list of positive integers n, one per line. The end of the input will be indicated by an integer value of zero. Notice:For each integer in the input n(n<10000).
 

Output
Output n^n's digital root on a separate line of the output.
 

Sample Input
 
 
2 4 0
 

Sample Output
 
 
4 4
 

Author
eddy

九余数定理:一个数对9取余所得为九余数。一个数的九余数等于该数的各位和对9取余。

#include <stdio.h>

int main()
{
    int n, i, ans;
    while(scanf("%d", &n), n){
        ans = 1;
        for(i = 1; i <= n; ++i)
            ans = n * ans % 9;
        if(!ans) ans = 9;
        printf("%d\n", ans);
    }
    return 0;
}


版权声明:本文博主原创文章,博客,未经同意不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4916221.html,如需转载请自行联系原作者


相关文章
|
2月前
|
缓存 人工智能 监控
MCP资源管理深度实践:动态数据源集成方案
作为一名深耕AI技术领域多年的开发者,我见证了从传统API集成到现代化协议标准的演进历程。今天要和大家分享的MCP(Model Context Protocol)资源管理实践,是我在实际项目中积累的宝贵经验。MCP作为Anthropic推出的革命性AI连接标准,其资源管理机制为我们提供了前所未有的灵活性和扩展性。在过去的几个月里,我深度参与了多个企业级MCP项目的架构设计和实施,从最初的概念验证到生产环境的大规模部署,每一个环节都让我对MCP资源管理有了更深刻的理解。本文将从资源生命周期管理的角度出发,详细探讨文件系统、数据库、API等多种数据源的适配策略,深入分析实时数据更新与缓存的最佳实践
81 0
|
ARouter 索引
|
NoSQL Redis Ruby
redis高可用集群搭建
redis高可用集群搭建
166 0
|
前端开发 JavaScript 容器
react组件化开发详解
react组件化开发详解
207 0
|
JSON 监控 安全
DustSquad APT组织针对乌兹别克斯坦的活动分析
伸向中亚地区的触手——DustSquad APT组织针对乌兹别克斯坦的活动分析
|
JavaScript 数据安全/隐私保护
Node.js:MD5加密字符串
Node.js:MD5加密字符串
132 0
|
JavaScript 前端开发 中间件
Vite入门从手写一个乞丐版的Vite开始(上)
本文会通过手写一个非常简单的乞丐版`Vite`来了解一下`Vite`的基本实现原理。
271 0
Vite入门从手写一个乞丐版的Vite开始(上)
|
Java jenkins 应用服务中间件
Jenkins:从SVN拉取Maven项目
Jenkins:从SVN拉取Maven项目
Jenkins:从SVN拉取Maven项目
Java学习路线-21:国际化Locale、ResourceBundle、MessageFormat
Java学习路线-21:国际化Locale、ResourceBundle、MessageFormat
227 0