How would I program special factorials into a calculator?
9 replies, posted
By "special" I mean double factorials (n!!), hyperfactorials (H(n)), etc. I don't really want specific code so much as an idea of what I should be doing. I don't really care about what language, just the general thing I should be doing.
What's their definition?
The double factorial of 6 (6!!) would be 6*4*2 as opposed to 6*5*4*3*2*1, triple would be 6*3...
The hyperfactorial of 6 (H(6)) would be (6^6)*(5^5)*(4^4)*(3*3)*(2*2)*(1^1).
The primorial regards only prime numbers, so 5 primorial would be 5*3*2*1, 7 primorial would be 7*5*3*2*1.
The superfactorial of 6 (6 $) would be 6!*5!*4!*3!*2!*1!.
That's the answer.
?
You just program in the definition, using simpler operations. Remember that you can write these generally using indexed sums.
Also remember that even exponential numbers will very quickly exceed the integer limit!
Depending on your inputs you need to use bigger data-types.
You said it's for a calculator, so I'd use some kind of "BigNum" data-type with (virtually) unlimited range.
For unlimited numeric data-types in .NET / C# there is BigInteger. And Java has one too.
If you need fractions you can use the BigRational class.
[url]http://bcl.codeplex.com/wikipage?title=BigRational&referringTitle=Home[/url]
Oh yeah, I seem to have forgotten what a function was when I asked this question.
[editline]9th August 2014[/editline]
Except primorials look painful.
I think the sieve of eratosthenes would be perfect for your concept of a 'primorial'.
With it, you can generate all primes up to some number you want.
In your case the limit is just your input-number.
Then you can just multiply the results of the sieve.
Thanks!
Sorry, you need to Log In to post a reply to this thread.