hdu 1163 Eddy's digital Roots
478 ワード
テーマリンク:http://acm.hdu.edu.cn/showproblem.php?pid=1163
九余の定理:
一つの数の各数字の和は10以下でなければ、10未満になるまで加算し続けます.この数対9に相当します.
コード:
九余の定理:
一つの数の各数字の和は10以下でなければ、10未満になるまで加算し続けます.この数対9に相当します.
コード:
#include <cstdio>
int main()
{
int n;
while(~scanf("%d",&n),n)
{
int t = 1;
for(int i = 1;i <= n;++i)
t = t * n % 9;
if(t == 0)
printf("9
");
else
printf("%d
",t);
}
return 0;
}