Sunday, March 24, 2013

project euler problem 053

Combinatoric selections

This is a simple problem. I do not remember what I did in my old code. But most probably I used the definition of nchoosek, which is quite costly in computation. 

This time I used pascal's triangle, which is much more efficient than my previous code.With my notebook, it takes less than 1ms.  

But when I tried the challenge with  projectEuler+ at hackerrank, it did not work since the value K can be 1e18, which has overflow issue with 64bit integer. I finally use double to get it accepted!

Good simple problem.

No comments:

Post a Comment