hdu1163Eddy's digital Roots

来源:互联网 发布:iphone抢购软件 编辑:程序博客网 时间:2024/05/18 00:54

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163


九余数定理:

一个数的每位数字之和如果不小于10,那么就继续相加,直到小于10,相当于这个数对9取余。


代码:


#include <cstdio>int main(){    int n;    while(~scanf("%d",&n),n)    {        int t = 1;        for(int i = 1;i <= n;++i)            t = t * n % 9;        if(t == 0)            printf("9\n");        else            printf("%d\n",t);    }    return 0;}

0 0
原创粉丝点击