Thread: June 2020
View Single Post
Old 2020-07-05, 22:21   #17
Jan 2017

3·29 Posts

Here's the program I used:


from gmpy2 import is_prime

def rec(n, target, used=set(), res=1, divsum=1, last1=None, last2=None):
    if n == 1:
        if divsum - res == target:
        if 2 not in used and divsum * 3 - 2*res == target:
    p, i = divs[n]
    e = p-1
    if n % e == 0:
        rec(n//e//p**i, target, used, res*p**(i+1), divsum*((p**(i+2)-1)//(p-1)))
    r = n // p
    for k in divisors(r):
        if p == last1 and k >= last2:
        t = k*p + 1
        if t in primes and t not in used:
            rec(r//k, target, used, res*t, divsum*(t+1), p, k)

factors = [(2, 18), (3, 3), (7, 2), (11, 1), (13, 1), (47, 1), (3169, 1), (8887, 1), (66643, 1), (72161, 1), (2495839, 1), (3847619, 1)]
target = 12142680281284711468101282998309016699980172

divs = {1:None}
for p, i in factors:
    prev = list(divs.keys())
    for j in range(1, i+1):
        pp = p ** j
        for d in prev:
            divs[d * pp] = (p, j)

def divisors(n, divs=divs):
    if n == 1:
        yield 1
    p, i = divs[n]
    pows = [1]
    for j in range(i):
    for d in divisors(n // pows[-1]):
        for m in pows:
            yield d * m

primes = set(d+1 for d in divs if is_prime(d+1))

rec(max(divs), target)
Given the number of smaller relative primes, RP=3031634148236289733373855928919180891127808, the program
finds all possible numbers for which euler_phi(n) equals this given value, and checks whether the divisor sum has the desired property. Since each prime power factor p^i in n produces a factor of (p-1)p^(i-1) in RP, it follows that (p-1) divides RP, and p is of the form d+1 for some divisor d or RP. This limits the set of primes possibly appearing in n to that set.

Thus the problem essentially becomes a packing problem - find a subset of powers of those primes such that the factors of (p-1)p^(i-1) add up to match exactly those in RP. The program iterates through possible solutions by trying different ways to select a prime power for n that reduces or eliminates the largest remaining prime factor in RP, then recursively solving the remaining values.

There are two separate cases - eliminating a factor p with p^i with i > 1 (under "if n% e == 0:") and eliminating it a single larger prime of the form k*p+1.

The "used" set is needed to avoid a case like 3^2 being used to eliminate a factor of 3 from RP, then trying to use 3 again to eliminate a factor of 2.

The program is careful to avoid repeating work by trying the same solution again. It won't try both selecting 2 and then 3, and later 3 then then 2. Eliminating a factor p with a power p^i with i > 1 always eliminates all the remaining powers of p, so it'll always be the last operation for that prime. The "last1" and "last2" arguments are used to ensure that factors removing same prime are in decreasing order - to eliminate powers of 2, adding 5 then 3 is allowed, but not vice versa.

The divisor sum is also calculated recursively, as it can also be expressed as a product of independent terms from each p^i factor in n.
uau is offline   Reply With Quote