HFUN - H Function

no tags 

The issue of this problem is to find out the value for H(N), where H(N) is the sum of all digits of N, but if H(N) > 9 then H(N) = H(H(N)). Rather it is want that you find H(N!).

1 <= T <= 300000

0 <= N <= 1000000

Input

T
N1
N2
...
NT

Output

H(N1!)
H(N2!)
...
H(NT!)

Example

Input:
2
1
5

Output:
1
3

hide comments
numerix: 2012-09-03 18:17:29

@Mitch: Explanation e.g. here: www.spoj.pl/forum/viewtopic.php?f=20&t=5918

Mitch Schwartz: 2012-09-02 21:18:57

There's something strange with the input formatting. In Python, int() gives AC, but eval() gives NZEC.

@numerix: Thank you for explaining.

Last edit: 2012-09-04 00:30:03
isak: 2011-06-19 03:28:09

N can be 10^6 and we have to calculate h(N!) !!!

Piotr KÄ…kol: 2010-09-11 11:36:05

Why not increase time limit to 5sec? For Ruby 3sec are not enought.


Added by:leandro
Date:2010-02-23
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ADA95 ASM64 BASH BF C99 CLPS LISP sbcl LISP clisp D ERL HASK ICK LUA NEM NICE OBJC OCAML PIKE PRLG-swi SCALA SCM guile SCM qobi ST SQLITE TCL WHITESPACE
Resource:Own Problem