SQUA_REV - Revenge of the squares

Given a number calculate the product N of their digits bigger than zero. The output is the number R of different (!) presentations of N in the form A*A+B*B with A and B being positive integers including zero.

Input

Twenty tests with one positive integer < 10^20.

Output

Print the illustrated above number R for each test.

Example

Input:
5
7
78185824586267361855 Output: 1
0
3

Added by:HWK
Date:2011-02-25
Time limit:1.096s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2017-11-17 12:26:08
Enjoyed the research and analysis, but applying directly what I learned gave WA. Had to observe pattern and patch my solution up accordingly. There's a connection between odd B and a0 that Wolfram doesn't frame correctly. A lot of people who ACd in short time also have WA submission first, wondering if they've run into this as well.
2015-03-19 22:19:23 :D
On formula questions. It's a fair query, since theorems used here are very advanced. Fermat two squares theorem is the base, but there is a specific version / implication that was critical for my solution. It's pretty easy to find on the net, but you must know what you're looking for. So you're still required to do some analysis here and not just apply the formulas. At least that was the case with my program.
2012-01-28 19:50:46 .
plz check my soln.. ID 6410182..n tell me what's wrong in this?
and wat does number R of different (!) presentations means?? plz elaborate
2011-06-08 02:51:23 Santiago Palacio
Thanks! finally got it!
2011-06-07 19:01:18 HWK
99999999999999999999 -> 1
2011-06-07 18:15:18 Santiago Palacio
What is the answer for 99999999999999999999? or any nasty test case please, i'm getting WA.

Last edit: 2011-06-07 18:36:17
2011-06-06 11:33:03 HWK
As string. ;-)
2011-06-06 04:21:02 Santiago Zubieta
How is it possible to read such a number outside of 2^64 :O?
2011-05-01 13:47:38 HWK
It seems so. You should look for it. ;-)

Last edit: 2011-05-26 15:11:24
2011-04-30 23:29:16 sandeep pandey
how people got accepted in 0.00sec.
mine got accepted 3.65sec.
is there is any formula???
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.