you need other methods to solve this problem (maths / smart brute force search / etc)?
It has an very very easy way to solve,but needs prove.
It takes O(n) time.
hint:
write down several solution of the number.
like 5=2+3 and so on.
31=2+3+5+6+7+8;
try to find out what common they have.