f=lambda a,b,s=0:b/a and 2*a*s+f(a+1,b,s+a) for (a,b) in (5,9), (91,123), (1,10): print '%2d %3d -> %8d' % (a,b,f(a,b))
Standard input is empty
5 9 -> 970 91 123 -> 12087152 1 10 -> 2640
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!