f(n)实际就是n%9
但要注意n==0实际是9
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h>
int ab[1009];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i,a;
__int64 b;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&ab[i]);
b=ab[n-1]%9;
for(i=1;i<n;i++)
{
b=(b+1)*ab[n-1-i]%9;
}
if(b==0)//注意b==0时
b=9;
printf("%I64d\n",b);
}
}