using System; using System.Collections.Generic; using System.Numerics; namespace A327887 { class Program { static void Main(string[] args) { for (int n = 1; n <= 5000; n++) { t = new BigInteger[n]; p = new BigInteger[n]; for (long v=1; ; v++) { if (ExtendWith(+v)) { Console.WriteLine("{0} {1}", n, +v); break; } else if (ExtendWith(-v)) { Console.WriteLine("{0} {1}", n, -v); break; } } } } static bool ExtendWith(long v) { if (!Seen(v)) { pp.Clear(); pp[0] = true; t[0] = v; p[0] = v; bool ok = true; for (int k = 1; k < t.Length; k++) { t[k] = t[k - 1] - d[k - 1]; if (Seen(t[k])) { ok = false; break; } p[k] = p[k - 1] + t[k]; if (pp.ContainsKey(p[k])) { ok = false; break; } else { pp[p[k]] = true; } } if (ok) { d = t; for (int k = 0; k < t.Length; k++) { See(d[k]); } return true; } } return false; } /// /// Last diagonal. /// static BigInteger[] d = { }; /// /// Next diagonal. /// static BigInteger[] t = null; /// /// Partial sums of t. /// static BigInteger[] p = null; /// /// Partial sums of t. /// static Dictionary pp = new Dictionary(); static bool Seen(BigInteger v) { return bigSeen.ContainsKey(v); } static void See(BigInteger v) { if (Seen(v)) { throw new ApplicationException("Already seen: " + v); } bigSeen[v] = true; } static readonly Dictionary bigSeen = new Dictionary(); } }