118. Digital Root



118. Digital Root

time limit per test: 0.25 sec.
memory limit per test: 4096 KB

Let f(n) be a sum of digits for positive integer n. If f(n) is one-digit number then it is a digital root for n and otherwise digital root of n is equal to digital root off(n). For example, digital root of987 is 6. Your task is to find digital root for expressionA1*A2*…*AN + A1*A2*…*AN-1 + … + A1*A2+ A1.

Input

Input file consists of few test cases. There is K (1<=K<=5) in the first line of input. Each test case is a line. Positive integer numberN is written on the first place of test case (N<=1000). After it there areN positive integer numbers (sequence A). Each of this numbers is non-negative and not more than109.

Output

Write one line for every test case. On each line write digital root for given expression.

Sample Input

1
3 2 3 4

Sample Output

5


将一个数的各位相加得到f(n),如果f(n)为1位,则f(n)为n的digital root,否则n的digital root为f(n)的digital root

给出一个数组A,求A1*A2*…*AN + A1*A2*…*AN-1 + … + A1*A2+ A1  的digital root

样例理解: A1 = 2, A2 = 3, A3 = 4             2*3*4 + 2*3 + 2 = 32    f(32) = f(5) = 5


把题目转化成: A1 + A1*A2 + A1*A2*A3 + A1*A2*A3的形式非常好看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值