Logarithm of the Factorial Pt 2

f ( x ) = 10 log x x ! \large{ f(x) = \lfloor 10\log_x x! } \rfloor

Consider the inverse of f f , g ( x ) = f 1 ( x ) g(x) = f^{-1}(x) . Each line of this 1000 line text file contains an integer i i , 2 i 2 × 1 0 10 2 \leq i \leq 2 \times 10^{10} . Find g ( i ) \sum g(i) .

Details and Assumptions

  • x \lfloor x \rfloor is the floor function. ie 123456.789 = 123456 \lfloor 123456.789 \rfloor = 123456 .

  • Here is an easier version of this problem.


The answer is 1025890576273.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Mark Hennings
Dec 15, 2015

The following Delphi code calculates g ( u ) g(u) , provided that u u is in the range of f f , (for safety) setting g ( u ) = 1 g(u) = -1 if the solution is not found. This routine determined all 1000 1000 values quickly. Adding the answers to get 1025890576273 1025890576273 was elementary.

function TForm1.LnGamma(x: Extended): Extended;
const stp =   2.50662827465;
       c1  =  76.18009173;
       c2  = -86.50532033;
       c3  =  24.01409822;
       c4  =  -1.231739516;
       c5  =   1.20858003E-3;
       c6  =  -5.36382E-6;
var ser : Extended;
begin
 ser := 1.0 + c1 / x + c2 / (x + 1.0) + c3 / (x + 2.0) +
          c4 / (x + 3.0) + c5 / (x + 4.0) + c6 / (x + 5.0); 
Result := (x - 0.5) * ln( x + 4.5) - x - 4.5 + ln( stp * ser);
end;

function TForm1.MyF(u: Int64): Int64;
begin
Result := Trunc(10*LnGamma(u+1)/Ln(u));
end;

function TForm1.MyG(u: Int64): Int64;
var
a: Double;
i: Int64;
j: Integer; 
begin
a := 20; 
while MyF(Trunc(u/(a-1))) < u do a := a - 1;
while MyF(Trunc(u/(a-0.1))) < u do a := a - 0.1;
while MyF(Trunc(u/(a-0.01))) < u do a := a - 0.01;
while MyF(Trunc(u/(a-0.001))) < u  do a := a - 0.001; 
while MyF(Trunc(u/(a-0.0001))) < u do  a := a - 0.0001;
while MyF(Trunc(u/(a-0.00001))) < u do a := a - 0.00001;
i := Trunc(u/a);
Result := -1;
for j := 0 to 100000 do
  if MyF(i+j) = u then
   begin
     Result := i+j;
     break;
   end;
end;

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...