View previous topic :: View next topic |
Author |
Message |
deepeshk79 Beginner
Joined: 20 Jun 2003 Posts: 112 Topics: 48 Location: Bangalore
|
Posted: Sun Jul 02, 2006 5:34 am Post subject: Fastest way to calculate Factorial of 285714? |
|
|
Hi All,
This is a general question in computers
Quote: |
What is the fastest way to compute 285714! (i.e. the factorial of 285714)?
|
Any thoughts ....
Deepesh |
|
Back to top |
|
 |
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Sun Jul 02, 2006 6:11 am Post subject: |
|
|
Here is my REXX solution:
Code: | /* REXX */
NUM = 285714
SAY FACT(NUM)
EXIT
FACT: PROCEDURE
PARSE ARG N
F = 1
DO J = 2 TO N; F = F * J; END
RETURN F |
O.
________
Honda CBR900RR
Last edited by ofer71 on Sat Feb 05, 2011 11:36 am; edited 1 time in total |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun Jul 02, 2006 1:58 pm Post subject: |
|
|
deepeshk79,
Do you really need that Big of a number? Anyway check this link which explains some of the techniques
Fast Factorial Functions
Btw cobol offers an Intrinsic function FACTORIAL , but is only limited to 28! or 29! with extend compiler option
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
deepeshk79 Beginner
Joined: 20 Jun 2003 Posts: 112 Topics: 48 Location: Bangalore
|
Posted: Mon Jul 03, 2006 7:33 am Post subject: |
|
|
Thanks Kolusu for the link.
Also Ofer thanks for your REXX code. |
|
Back to top |
|
 |
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Mon Jul 03, 2006 1:31 pm Post subject: |
|
|
deepeshk79,
Have you observed something magical about the number, 285714/2 ?
Take 142857. Multiply it by 2, note the product. Then by 3, note the product. Continue till 6. You will see that the product always consists of the digits 1,4,2,8,5 and 7 rotated in a cyclical fashion.
What happens when multiplied by 7 ? Another interesting number !
Enjoy !
 _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
 |
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Tue Jul 04, 2006 1:10 am Post subject: |
|
|
That's because 142857 is a Cyclic Number. To read more about it, refer to the following link.
O.
________
[URL=http://www.bmw-tech.org/wiki/BMW_3_Series_(E46)]3 Series (E46)[/URL] |
|
Back to top |
|
 |
|
|