using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace D19._2 { class Program { static void Main(string[] args) { var ba = new List(); for (var j = 1; j <= int.Parse(args[0]); ++j) ba.Add(j); int i = 0; while (ba.Count > 1) { var target = i + ba.Count / 2; if (target >= ba.Count) target -= ba.Count; ba.RemoveAt(target); if (target > i) i++; if (i >= ba.Count) i -= ba.Count; } Console.WriteLine($"The answer is : {ba.First()}"); } } }