HDU 1163 Eddy's digital Roots

来源:互联网 发布:数据泄露防护系统破解 编辑:程序博客网 时间:2024/05/21 20:23

题目地址:点击打开链接

思路: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;}


0 0
原创粉丝点击