[Community puzzle] Factorial vs Exponential

This topic is about the puzzle Factorial vs Exponential.

Feel free to send your feedback or ask some help here!

Making some progress, passes the first three tests, but on the fourth test I get this response:

Found: “2096 1594 1192 300 1446 1180 2646 6\096 1594 1192 300 1446 1180 2”
Expected: “2096 1594 1192 300 1446 1180 2646 5\096 1594 1192 300 1446 1180 2”

What does the 6\096 mean? Or the 5\096?

seems like a bug. You can see the tests by the way when you solve puzzles (click the right top button in the tests section).
Can you reproduce it all the time?

Yes, it behaves the same way every time. Program passes ALL tests except number 4. Tried turning off my program’s debug output and it made no difference. Noticed that the sequence of numbers after the slash is identical to the numbers at the beginning, if you start with the second digit.

can you PM me your code?

I’m using C++. I’ve made my variables long double. But the exponential goes infinite before the factorial catches up on test cases 4 and 5. Is there something bigger than long double? Is there some trick to figure this out that doesn’t involve calculating and comparing A^N and N!? I’m stuck. Thanks for any help you can give me.

MarkWyz, think about mathematical functions that make big numbers smaller…


Thanks for the hint. I finally got it to work 100%.

1 Like

Can someone help me, I’m stuck on test case 5.
Here’s my c# code:

Increase kmax maybe ? Try 30000

Has anyone solved this for with Python for Test Case #5 Huge Float Values? I’ve get about halfway done in 6 seconds and then get the error.

Process has timed out. This may mean that your solution is not optimized enough to handle some cases.

I’m using a binary search and setting the lower & upper limits based upon previous results each time. Test Case #4 Bigger Float Values completes in under 2 seconds. Wondering if I need to use the gmpy module to complete this…

No, no need. See selenae answer 5 posts above.

Thanks and wow not what I expected.

I had cached the factorials as I calculated them (as the min/max could re-use them for different numbers) but that wasn’t the problem. (Thought for sure that was the long operation and I don’t think that simplifies at all).

Had to take the Log of both sides and then use N*math.log(a) instead of aN in my comparison. This completed within the time limit where as aN would not.

I don’t remember my calculus that well, but I guess the libraries use a Taylor Series to calculate the Log function. Where as the ** operation is performed recursively when an integer is used? Seems odd as I’d expect that operation to convert/simply with natural log functions which could use Taylor Series.

Doesn’t make sense, so maybe I don’t quiet understand it, but problem solved & solution passed!

Thanks Kirbiby & selenae

Again a mathematical puzzle…

two choices : you know the right theorem and you can solve the puzzle easily or you don’t know and you just go to an other puzzle.

1 Like

Fixed. :grinning:

1 Like

You are absolutely right @nicola1.
I did read the wiki about the factorials,
and found an amazing way to solve the problem.
That, made the problem extremely simple!


Great choice!
That helps :wink:

Hi !

I haven’t hardcoded any part of my solution and I can run my code on larger test cases, but I keep failing the last validation. Not in the test cases, but in the evaluation only. I don’t suppose there is any way of knowing what went wrong?

Thanks for any idea,


Maybe your algorithm times out.

1 Like

Hmm, interesting. Indeed, I would not have seen that the error message was different… I’ll try reprogramming with memorization, and see if it helps. Thanks!