Analysis
首先,答案必定就是题目给定式子除以9所得的余数,那么求出给定式子的值就行了。我们可以把式子转化为(A1*(1+A2*(1+A3(……(1+An)……))))的形式,边做边模就可以了。
Accepted Code
var
a:array[1..1000] of longint;
testcase,n,i,t:longint;
begin
read(testcase);
while testcase>0 do
begin
dec(testcase);
read(n);
for i:=1 to n do
read(a[i]);
t:=0;
for i:=n downto 1 do
t:=(t+1)*(a[i] mod 9) mod 9;
t:=(t+8) mod 9+1;
writeln(t);
end;
end.