// The Magma program below finds terms of OEIS A350878 // ("Integers m that divide the sum of values d*p < m, // where d is a divisor of m, p is a prime, and d*p // does not divide m"). // // Running on the Online Magma Calculator at // // http://magma.maths.usyd.edu.au/calc/ // // it finds all terms < M = 500000 in about 18 seconds. // // Note about memory usage: the algorithm implemented in the // program is simple, but its use (on some platform other than // the time-limited Online Magma Calculator) to try to extend // the sequence much beyond the search limit indicated in the // current (Feb 05 2022) draft of OEIS sequence A350878 would // require a significant amount of memory; the program uses an // array S that stores M integers, the largest of which is the // sum of the first M primes. // //////////////////////////////////////////////////////////////// // // Program written by Jon E. Schoenfield (who still knows only // enough Magma to barely get by), Feb 05 2022. // //////////////////////////////////////////////////////////////// M := 500000; // upper limit to which to search P := PrimesUpTo(M); a := []; // array for storing terms as they're found // Create and populate array S: // S[m] = sum of primes <= m S := [0]; m := 2; for p in P do while m lt p do S[m] := S[m-1]; m +:= 1; end while; S[p] := S[p-1] + p; m +:= 1; end for; while m le M do S[m] := S[m-1]; m +:= 1; end while; for m in [1..M] do // Determine whether m is a term Sum := 0; D := Divisors(m); PD := []; // will store prime divisors of m for j in [1..#D-1] do // omit largest divisor (m itself) d := D[j]; // Increase Sum by the sum of all // products d*p < m where p is prime Sum := Sum + d * S[(m-1) div d]; if IsPrime(d) then PD[#PD+1] := d; end if; end for; // Decrease Sum by the sum of all // products d*p < m where p is prime AND d*p | m for p in PD do for d in D do t := d*p; if t ge m then break; end if; if m mod t eq 0 then Sum := Sum - t; // (runs faster than "Sum -:= t;") end if; end for; end for; if Sum mod m eq 0 then // m is a term a[#a+1] := m; end if; end for; a; // output all terms found