using System; using System.Collections.Generic; using System.Linq; namespace A353918 { /// <summary> /// a(n) is the number of ways to write n as a sum of distinct terms of A353889. /// </summary> class Program { static void Main() { long[] a = new long[1 << 14]; List<long> A353889 = new List<long>(); HashSet<long> sums = new HashSet<long>(); sums.Add(0); // empty sum long total = 0; // total of known values long limit = 1; // power of two >= total + value to test for (long v = 1; v < a.Length; v++) { while (limit < v + total) { limit *= 2; } bool keep = true; for (long powerOf2 = limit; powerOf2 >= v; powerOf2 /= 2) { if (sums.Contains(powerOf2 - v)) { keep = false; break; } } if (keep) { A353889.Add(v); total += v; foreach (long s in sums.ToArray()) { sums.Add(s + v); } } } Explore(A353889.ToArray(), a, 0, 0); for (long n = 0; n < a.Length; n++) { Console.WriteLine($"{n} {a[n]}"); } } static void Explore(long[] values, long[] nb, long sum, long pos) { nb[sum]++; while (pos < values.Length && sum + values[pos] < nb.Length) { Explore(values, nb, sum + values[pos], pos + 1); pos++; } } } }