from math import sqrt

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
          43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];

def factorize(n):
    """Returns prime factorization of n.
    e.g. factorize(12) returns [2, 2, 3]"""

    factors = []
    for p in primes:
        if p > n:
            break
        while n % p == 0:
            p_count += 1
            n /= p
        count *= (p_count + 1)
    return count

sums = [11, 17, 23, 27, 29, 35, 37, 41, 47, 51, 53, 57,
        59, 65, 67, 71, 77, 79, 83, 87, 89, 93, 95, 97]

sums_info = {}
for product in range(6, 2451):
    # Skip squares and fourth powers of primes
    r = sqrt(sqrt(product))
    if (int(r) in primes and int(r)**4 == product) or \
       (int(r * r) in primes and int(r * r)**2 == product):
        continue

    factorizations = 0
    for factor1 in range(2, int(sqrt(product)+1)):
        factor2 = product / factor1

        # Skip if factor1 isn't a factor or both factors are primes
        if product % factor1 != 0 or (factor1 in primes and factor2 in primes):
            continue

        # Skip if there are two possible factorizations such that the
        # sum of factors in each factorization is a possible sum with S
        if factor1 + factor2 in sums:
            factors = factor1, factor2
            factorizations += 1
            if factorizations > 1:
                break
    else:
        if factorizations == 1:
            s = factors[0] + factors[1]
            if s not in sums_info:
                sums_info[s] = [factors]
            else:
                sums_info[s].append(factors) 

            print 'If P has %d: X = %d, Y = %d, S has %d' % \
                  (product, factors[0], factors[1], s)
print

for sum in sums_info:
    if len(sums_info[sum]) == 1:
        print 'X = %d and Y = %d has a unique sum.' % sums_info[sum][0]

