Hi, i’m stuck with the validation test 4 of this problem. (It’s a Community Puzzle)
My code validates all the test cases except this one (and not with an hardcoded solution ^^)
I think the complexity of my solution is good (using prime factors and freq…)
I identify the special case “a = 1” (with answers like 0, Integer.MAX_VALUE, Double.POSITIVE_INFINITY, etc.)
I had the same issue yesterday, the Validation Test 4 wouldn’t pass.
But everything else would, and the algorithm looked definitely correct.
As you said, one possible way to solve this puzzle is by looking at the prime factors.
You probably have some kind of sieve function that generates prime numbers under a certain limit?
Well, I have such a function and what it does is compute the list of prime numbers below limit. This function allocates a big array of size limit to do the lookup.
In the beginning I chose limit to be max(a, b) + 1 to only generate the prime numbers that are necessary. This passed all the validation tests except the last one.
But by using limit = 10 ^ 7 + 1 instead, the last test would just pass!
However, trying with limit = 10 ^ 8 gives a MemoryError directly in the IDE (using Python).
So my guess is that the input used for the last test case doesn’t respect the constraints mentioned in the problem statement (1 ≤ A, B ≤ 10^7), meaning either A or B is above 10^7.
Or just a general memory error, depending on how many objects you allocate (you seem the be using Java).
Probably something worth checking!
It is indeed enough.
In my case, I implemented a simple version of the sieve of Eratosthenes, which allocates an array of booleans to keep track of the prime numbers. For example: if B = 12345678, it will allocate an array of 12345678 booleans.
And creating such a big array makes the program crash with a memory error.
But at the same time, creating a fixed-size array of 10^7 booleans works and fits the memory limit.
What I love about this puzzle is that my first reaction was similar to the above (Prime numbers, sieve, fancy number theory), but after some thought and looking into the essence of the problem - a beautiful and simple solution exist that doesn’t require any big arrays or complex calculations.
All it requires is looking at the core of the question here, and remembering the basic rules of “power of n”
Still no correction after two weeks.
Two edge cases identified by MMMAAANNN and me.
This puzzle became a puzzle of the week and still no answer coming from the staff, that’s pretty awful.
Noone read the forum?