hdu 1163

来源:互联网 发布:淘宝商城家具床 编辑:程序博客网 时间:2024/05/17 22:24

题目链接: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;}
0 0
原创粉丝点击