Apologies for the lateness of this solution but after much counting of brackets I submit a program for an HP17bII+.
SSMC=0*SIGMA(I:0:9:1:
0*L(B:0) + 0*L(C:ALOG(9-I) + 0*L(A:9000000000)
+0*L(D:MOD(IP(G(A)/G(C)):10) +
+0*SIGMA(J:0:9:1:L(X:MOD(IP(G(A)/ALOG(J)):10))
+0*IF(G(X)=I:L(B:G(B)+1):G(B)))
+0*IF(G(D)<>G(B):
L(A:G(A)-G(D)*G(C)+G(B)*G(C)):G(A)))
+ G(A)
Do not forget to register the variables i.e. Y=A+B+C+D+X. The result is obtained after 5 interations. This shows what can be done on a HP17bII+ with a reasonable amount of patience!
Chris Dean
12345