https://code.google.com/codejam/contest/5264487/dashboard
Simple. Just calculate the number of blue lights between [1, k].
Read this leetcode discuss topic for explanation.
If the smallest number is x.
Then, just calculate the number of pairs (p,q,r) where px+q(x+1)+r(x+2)=n
.
for each p in [1, n/x], q(x+1)+r(x+2)=n-px
.
Obviously, (q+r)(x+1)+r=n-px
, that is, r%(x+1)=(n-px)%(x+1)
.
So, we just need to calculate how many r in [0, (n-px)/(x+1)] satisfies r%(x+1)=(n-px)%(x+1)
.
This problem is hard, really hard.
I don't know how to solve or explain it...
If you can solve this problem, please contact me at [email protected].