Sum-product number

From testwiki
Jump to navigation Jump to search

Template:Short description Template:Confuse A sum-product number in a given number base b is a natural number that is equal to the product of the sum of its digits and the product of its digits.

There are a finite number of sum-product numbers in any given base b. In base 10, there are exactly four Template:Nowrap numbers Template:OEIS: 0, 1, 135, and 144.[1]

Definition

Let n be a natural number. We define the sum-product function for base b>1, Fb:ℕ→ℕ, to be the following:

Fb(n)=(∑i=1kdi)(∏j=1kdj)

where k=⌊logbn⌋+1 is the number of digits in the number in base b, and

di=nmodbi+1−nmodbibi

is the value of each digit of the number. A natural number n is a Template:Nowrap number if it is a fixed point for Fb, which occurs if Fb(n)=n. The natural numbers 0 and 1 are trivial Template:Nowrap numbers for all b, and all other Template:Nowrap numbers are nontrivial Template:Nowrap numbers.

For example, the number 144 in base 10 is a sum-product number, because 1+4+4=9, 1×4×4=16, and 9×16=144.

A natural number n is a sociable sum-product number if it is a periodic point for Fb, where Fbp(n)=n for a positive integer p, and forms a cycle of period p. A Template:Nowrap number is a sociable Template:Nowrap number with p=1, and an amicable Template:Nowrap number is a sociable Template:Nowrap number with p=2.

All natural numbers n are preperiodic points for Fb, regardless of the base. This is because for any given digit count k, the minimum possible value of n is bk−1 and the maximum possible value of n is bk−1=∑i=0k−1(b−1)i. The maximum possible digit sum is therefore k(b−1) and the maximum possible digit product is (b−1)k. Thus, the Template:Nowrap function value is Fb(n)=k(b−1)k+1. This suggests that k(b−1)k+1≥n≥bk−1, or dividing both sides by (b−1)k−1, k(b−1)2≥(bb−1)k−1. Since bb−1≥1, this means that there will be a maximum value k where (bb−1)k≤k(b−1)2, because of the exponential nature of (bb−1)k and the linearity of k(b−1)2. Beyond this value k, Fb(n)≤n always. Thus, there are a finite number of Template:Nowrap numbers, and any natural number is guaranteed to reach a periodic point or a fixed point less than bk−1, making it a preperiodic point.

The number of iterations i needed for Fbi(n) to reach a fixed point is the Template:Nowrap function's persistence of n, and undefined if it never reaches a fixed point.

Any integer shown to be a sum-product number in a given base must, by definition, also be a Harshad number in that base.

Extension to negative integers

Sum-product numbers can be extended to the negative integers by use of a signed-digit representation to represent each integer.

Programming example

The example below implements the sum-product function described in the definition above [[Cycle detection|to search for Template:Nowrap numbers and cycles]] in Python.

def sum_product(x: int, b: int) -> int:
    """Sum-product number."""
    sum_x = 0
    product = 1
    while x > 0:
        if x % b > 0:
            sum_x = sum_x + x % b
            product = product * (x % b)
        x = x // b
    return sum_x * product

def sum_product_cycle(x: int, b: int) -> list[int]:
    seen = []
    while x not in seen:
        seen.append(x)
        x = sum_product(x, b)
    cycle = []
    while x not in cycle:
        cycle.append(x)
        x = sum_product(x, b)
    return cycle

See also

References

Template:Reflist

Template:Classes of natural numbers