SGU 118 — Digital root
这道题其实就是等价于问A1+A1*A2+…+A1*A2*…*An对9的余数,注意如果余数是0的话就输出9.
不过这里我有一点疑问,为什么0的digital root应该是9才能AC…
难道是题目出的有问题…
囧.
{
SGU 118; Digital Root
- sqybi’s code
- Why AC… what should root(0) be?!
}
//for my winsty
program sgu118_sqybi;
var
n, s, t, x, i, times, cases: longint;
function root(x: longint): longint;
begin
if x mod 9 = 0 then root := 9 else root := x mod 9;
end;
begin
readln(cases);
for times:=1 to cases do begin
read(n);
t := 0;
s := 1;
for i:=1 to n do begin
read(x);
s := root(s*root(x));
t := root(t+s);
end;
readln;
writeln(t);
end;
end.
阅读(53 次)