Talk:Special factorials

Revision as of 17:07, 16 March 2021 by Chunes (talk | contribs) (Demonstrate an efficient, readable reverse factorial algorithm)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Reverse factorial algorithm

I took a stab at translating the reverse factorial algorithm used in the Factor entry to Java. It should be almost as efficient as taking the factorial itself. <lang java>public static int rf(int n) {

   int a = 1;
   int b = 1;
   while (n > a) {
     b++;
     a = a * b;
   }
   if (a == n)
     return b;
   else return -1; //undefined
 }</lang>

--Chunes (talk) 17:06, 16 March 2021 (UTC)

Return to "Special factorials" page.