using System; using System.Collections.Generic; using System.Linq; class Program { class RangeInfo { public int Start {get; private set;} public int Last {get; private set;} public int Length { get { return Last - Start + 1; } } public RangeInfo(int start, int last) { this.Start = start; this.Last = last; } } static IEnumerable Solve726(int n) { int last = (int)(-1 + Math.Sqrt(1.0 + 8 * n) / 2); int first = 0; int d = last * (last + 1) / 2 - n; while (first <= last) { switch (Math.Sign(d)) { case -1: d += ++last; break; case 1: d -= first++; break; default: yield return new RangeInfo(first, last); d -= first++; break; } } } static void Main(string[] args) { int N = 2014; foreach (var x in Solve726(N)) { var r = Enumerable.Range(x.Start, x.Length).Select(n => n.ToString()); Console.WriteLine(string.Join(",", r.ToArray())); } } }