using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace A175342_A049988 { class Program { static void Main(string[] args) { new Program().DoIt(10000); } // A175342 Number of arithmetic progressions (where the difference between adjacent terms is either positive, 0, or negative) of positive integers that sum to n. // 1, 2, 4, 5, 6, 10, 8, 10, 15, 14, 12, 22, 14, 18, 28, 21, 18, 34, 20, 28, 38, 28, 24, 46, 31, 32, 48, 38, 30, 62, 32, 40, 58, 42, 46, 73, 38, 46, 68, 58, 42, 84, 44, 56, 90, 56, 48, 94, 55, 70, 90, 66, 54, 106, 70, 74, 100, 70, 60, 130, 62, 74, 118, 81, 82, 130, 68, 84, 120 // OFFSET 1 // A049988 Number of non-decreasing arithmetic progressions of positive integers with sum n. // 1, 2, 3, 4, 4, 7, 5, 7, 9, 9, 7, 14, 8, 11, 16, 13, 10, 20, 11, 17, 21, 16, 13, 27, 17, 18, 26, 22, 16, 35, 17, 23, 31, 23, 25, 41, 20, 25, 36, 33, 22, 46, 23, 31, 48, 30, 25, 52, 29, 38, 47, 36, 28, 57, 37, 41, 52, 37, 31, 71, 32, 39, 62, 44, 43, 69, 35, 45, 62, 57, 37, 79, 38 // OFFSET 1 // A175342(n) = 2*A049988(n) - A000005(n) it says in A175342 // sum = (n/2)*(a1 + an), or // sum = (n/2)*(2*a1 + (n-1)*d), from which // d = 2*(sum - a1*n)/n/n-1 // We also use // an = a1 + (n-1)*d public void DoIt(int max) { int over, under, d, countPos, countAll; List pos = new List(); List all = new List(); for (int sum = 1; sum <= max; sum++) { countPos = 0; countAll = 0; // The first term can vary between 1 and sum for (int a1 = 1; a1 <= sum; a1++) { // Vary the number of terms, and determine those where d is an integer for (int n = 1; n <= sum; n++) { over = 2 * (sum - a1 * n); under = n * (n - 1); if (under == 0) { if (over == 0) { // This progression has just 1 term countPos++; countAll++; } continue; // Take next n } if ((over % under) == 0) { // d is an integer d = over / under; // Only positive terms are allowed // if d >= 0 all terms are positive // but for d < 0 we must check that 'an' is positive (then all terms are positive) if ((a1 + (n - 1) * d) > 0) { // Found countAll++; if (d >= 0) { countPos++; } } } } } pos.Add(countPos); all.Add(countAll); } OEISBfilePrinter ppos = new OEISBfilePrinter("b049988.txt", 1, 10000, 1000); OEISBfilePrinter pall = new OEISBfilePrinter("b175342.txt", 1, 10000, 1000); for (int k = 0; k < pos.Count; k++) { ppos.Add(pos[k]); pall.Add(all[k]); } ppos.Close(); pall.Close(); } public class OEISBfilePrinter { int Offset; int MaxEntries; int MaxLength; StreamWriter w; public int Ix; public OEISBfilePrinter(string fn, int offset, int maxEntries, int maxLength) { Offset = offset; MaxEntries = maxEntries; MaxLength = maxLength; w = new StreamWriter(fn); Ix = 0; } public void Close() { if (w != null) { w.Close(); w = null; } } public void Add(long v) { if (w != null) { if (Ix + Offset <= MaxEntries) { w.WriteLine((Ix + Offset) + " " + v); Ix++; } else { Close(); } } } } } }