We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
the idea in this problem is to divide the bricks into horizontal blocks and evaluate the compensation using nCr, then break the blocks down into 4 vertical bricks until reach to no horizontal block remaining, and count the combination of each loop.
To optimize the speed of nCr, we could just simplify the rule into two for loops, one for the numerator and the other for the detonatorinstead of using 3 factorials.
Also, to optimize the prime number counting, we could store the prime numbers and divide on them instead of doing a loop for all possible combinations each time.
Red John is Back
You are viewing a single comment's thread. Return to all comments →
the idea in this problem is to divide the bricks into horizontal blocks and evaluate the compensation using nCr, then break the blocks down into 4 vertical bricks until reach to no horizontal block remaining, and count the combination of each loop.
To optimize the speed of nCr, we could just simplify the rule into two for loops, one for the numerator and the other for the detonatorinstead of using 3 factorials.
Also, to optimize the prime number counting, we could store the prime numbers and divide on them instead of doing a loop for all possible combinations each time.
here is my code using C language