且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

hdu 1163

更新时间:2022-08-13 08:49:30

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1163
hint:九余数定理

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

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

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int m,tmp;
    while(cin>>m,m)
    {
        tmp=m;
        for(int i=2; i<=m; i++)
        tmp=tmp*m%9;
        if(tmp == 0)
            cout<<"9"<<endl;
        else
            cout<<tmp<<endl;
    }
    return 0;
}