Hello Geoff;

Has this forum become the Project Euler cheat forum?

Geoff Canyon wrote:
f 2 3628800 0

That's the correct way to call it, and as far as I know, 3628789 is the right answer. Based on my checks with smaller numbers, 2 is a factor of N! roughly N times. For N = 2^X, 2 is a factor of N! N-1 times.

The N I'm interested in is 1,000,000,000,000, hence the reason for not just taking the factorial and letting J do the factoring ;-)


On Apr 12, 2008, at 9:19 PM, Devon McCormick wrote:
I don't know where you're going with this, but, just based on the minimal statement of the problem, I probably would have done it something like this
(for your example):

 2+/ . =q:!10
8

However, I'm guessing you can't use "q:" because it's a "large factorial".
That being the
case, I don't know how to use the function you provided as you give no
example.  That is, I tried the
obvious:

 !10
3628800
 f=: 2&{@:((0&{ , (0 , 2&{) + [: <. 1&{ % 0&{)^:_)
 f 2 3628800 0
3628789

which isn't right.

On 4/12/08, Geoff Canyon <[EMAIL PROTECTED]> wrote:

I've created a function to figure out how many times a large factorial
will have a given number as a factor.

So for example, !10 has 2 as a factor 8 times:

2  1
4  2
6  1
8  3
10 1

Here's the function I defined to calculate this:

f=: 2&{@:((0&{ , (0 , 2&{) + [: <. 1&{ % 0&{)^:_)

It takes three arguments: the factor, the factorial, and the starting
number for the factor-count, which should always be 0.

It divides the factorial number by the factor repeatedly, keeping track of
the sum of the quotients, and at the end outputs just the sum.

Is this a reasonable job of J programming? Is there a better way to have
coded this?

regards,

Geoff
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


--
------------------------------------------------------------------------
|\/| Randy A MacDonald       | APL: If you can say it, it's done.. (ram)
|/\| ramacd <at> nbnet.nb.ca |
|\ |                         | The only real problem with APL is that
BSc(Math) UNBF'83            | it is "still ahead of its time."
Sapere Aude                  |     - Morten Kromberg
Natural Born APL'er          |
-----------------------------------------------------(INTP)----{ gnat }-


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to