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.
Little Ashish's Huge Donation
Little Ashish's Huge Donation
Sort by
recency
|
27 Discussions
|
Please Login in order to post a comment
Given the sum of squares formula, the number of days to spend x candies is roughly the cube root of 3x. So I back off a few days from that estimate to be conservative and then iterate through until I find the right value.
c++ almost complete all test cases
This can be also solved using transtion matrix and approach similar to fibonacci series etc. problems. Transition matrix:
(0 1 0 2 1 0) - i^2
(0 0 0 1 0 0) - i-1
(0 0 0 1 1 0) - i
(0 0 0 0 1 0) - const 1
(0 1 0 2 1 1) - Sum(1 to i inclusive)
Initial vector for i=1: (1, 0, 1, 1, 1)
Then use efficient exponentitation to find relevant matrices and multiple. O(log n)
Use long int if you are getting runtime error
Thanks for sharing the information it was very helpful for me temple run 3