HDU 1163 Eddy's digital Roots

题目地址:点击打开链接

思路:9余数定理,详解地址:点击打开链接

AC代码:

#include <iostream>

using namespace std;

int main()
{
    int n,i;
    while(cin>>n)
    {
        if(n == 0)
            break;
        int temp = 1;
        for(i=0; i<n; i++)
        {
            temp  = (temp * n) % 9;
        }
        if(temp == 0)
            cout<<9<<endl;
        else
            cout<<temp%9<<endl;
    }
    return 0;
}


你可能感兴趣的:(HDU 1163 Eddy's digital Roots)