杭电1163 eddy's Digital Roots

版权声明:ACM代码随意转载。算法描述需备注来源。谢谢合作。 https://blog.csdn.net/Sensente/article/details/89791397

杭电1163 http://acm.hdu.edu.cn/showproblem.php?pid=1163

题目大意:

求n^n的数根(同九余数定理) 

AC代码:

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <stack>
#include <stdlib.h>
//#define DEBUG
using namespace std;
typedef long long ll;
ll a;
int main() {
    while(cin>>a) {
        if(a==0) return 0;
        int m=1;
        for(int i=0;i<a;i++) {
            m*=a;
            if(m>9) m%=9;
        }
        if(m==0) cout<<9<<endl;
        else cout<<m<<endl;
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Sensente/article/details/89791397
今日推荐