All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Factorial Sequence II (Posted on 2006-03-10)
To go along with Factorial Sequence, I present Factorial Sequence II. You can approximate the length of x! by multiplying x*log(x/e).

Now, using this knowledge, find the value at which the length of x! is equal to 1,000,000,000?

 See The Solution Submitted by Justin Rating: 4.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 1 of 3

The idea is to solve x*log(x/e) = 1,000,000,000.

If x is 130202808,  x*log(x/e) is 999999994.4440194, while if x is 130202809,  x*log(x/e) is 1000000002.55864. So the formula gives no answer that rounds exactly to 1,000,000,000.

Using a more precise formula,

log (x!) =  log(x) * (x + .5) +  (-x + 1/(12*x) - 1/(360*x^3) + 1/(1260*x^5)) / ln(10) + log(2*pi)/2

the values of x and len(x!) actually come out to:

x                 len(x!)
130202808     999999999
130202809     1000000008

so again there's no value that produces exactly length 1,000,000,000.

program used:

DECLARE FUNCTION log10# (x#)
DECLARE FUNCTION lxf# (x#)
CONST pi# = 3.14159265358979# + 3.24D-15
CONST twopi# = 2# * pi#
CONST e# = 2.71828182845904# + 5.24D-15
CONST loge10# = 2.30258509299404# + 5.68D-15
CONST einv# = 1# / e#
CONST radDeg# = 180# / pi#

CLS

DEFDBL A-Z

CLS
i = 40
f = 1.1

DO
DO
i = INT(i * f)
l = i * LOG(i / e#) / loge10#
a\$ = INKEY\$
LOOP UNTIL l >= 1000000000 OR a\$ = CHR\$(27)
IF a\$ = CHR\$(27) THEN EXIT DO
PRINT i, l, l / i
f = 1 - (f - 1) / 2
DO
i = INT(i * f)
l = i * LOG(i / e#) / loge10#
a\$ = INKEY\$
LOOP UNTIL l < 1000000000 OR a\$ = CHR\$(27)
IF a\$ = CHR\$(27) THEN EXIT DO
f = 1 + ABS(f - 1) / 2
PRINT i, l, l / i
LOOP UNTIL INKEY\$ = CHR\$(27) OR a\$ = CHR\$(27)
PRINT
j = i
FOR i = j - 3 TO j + 3
l = i * LOG(i / e#) / loge10#
PRINT i, l, l / i
NEXT

DO: LOOP UNTIL INKEY\$ = CHR\$(27)

i = 40
f = 1.1

DO
DO
i = INT(i * f)
l = INT(lxf#(i) + 1)
a\$ = INKEY\$
LOOP UNTIL l >= 1000000000 OR a\$ = CHR\$(27)
IF a\$ = CHR\$(27) THEN EXIT DO
PRINT i, l, l / i
f = 1 - (f - 1) / 2
DO
i = INT(i * f)
l = INT(lxf#(i) + 1)
a\$ = INKEY\$
LOOP UNTIL l < 1000000000 OR a\$ = CHR\$(27)
IF a\$ = CHR\$(27) THEN EXIT DO
f = 1 + ABS(f - 1) / 2
PRINT i, l, l / i
LOOP UNTIL INKEY\$ = CHR\$(27) OR a\$ = CHR\$(27)
PRINT
j = i
FOR i = j - 3 TO j + 3
l = INT(lxf#(i) + 1)
PRINT i, l, l / i
NEXT

DO: LOOP UNTIL INKEY\$ = CHR\$(27)

END

DEFDBL A-Z
FUNCTION log10# (x)
log10# = LOG(x) / loge10#
END FUNCTION

FUNCTION lxf# (x#)
IF x# < 171 THEN
fact# = 1
IF x# > 1 THEN
FOR i = 2 TO x#
fact# = fact# * i
NEXT
END IF
lo# = log10#(fact#)
ELSE
lo# = log10#(x#) * (x# + .5#)
lo# = lo# + (-x# + 1# / (12# * x#) - 1# / (360# * x# * x# * x#) + 1# / (1260# * x# * x# * x# * x# * x#)) / loge10#
lo# = lo# + log10#(twopi#) / 2#
END IF
lxf# = lo#
END FUNCTION

 Posted by Charlie on 2006-03-10 13:06:06

 Search: Search body:
Forums (0)