+ 2
void sumGivesN(int n){ int sum=0, min=1; for(int i=1; min<=n/2; ){ if(sum==n){ for(int j=min; j<i; j++) System.out.print(j + " "); System.out.println(); sum-=min++; }else if(sum>n) sum-=min++; else sum+=i++; } }
17th Oct 2017, 4:55 PM
Chriptus13
Chriptus13 - avatar