Home | Back to Contest Questions
Solution 26  by kstahmer

 Digits lemma: Suppose n is a positive integer and has decimal representation    n = a0 + a110 + a2102 + ... + am10m with am nonzero. Suppose f(x) is a nonnegative integer for x = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Define M = max { f(x) | x = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }. Then if n = f(a0) + f(a1) + f(a2) + ... + f(am) it follows: . Proof: Dividing the above inequality by m + 1 establishes our lemma.

The nontrivial answers are:

[b]1634 = 1^4 + 6^4 + 3^4 + 4^4

8208 = 8^4 + 2^4 + 0^4 + 8^4

9474 = 9^4 + 4^4 + 7^4 + 4^4[/b]

The below Java program was used to find these answers.

This code is adaptable.

For example, by changing POWER to 7, we have:

1 = 1^7

1741725 = 1^7 + 7^7 + 4^7 + 1^7 + 7^7 + 2^7 + 5^7

4210818 = 4^7 + 2^7 + 1^7 + 0^7 + 8^7 + 1^7 + 8^7

9800817 = 9^7 + 8^7 + 0^7 + 0^7 + 8^7 + 1^7 + 7^7

9926315 = 9^7 + 9^7 + 2^7 + 6^7 + 3^7 + 1^7 + 5^7

14459929 = 1^7 + 4^7 + 4^7 + 5^7 + 9^7 + 9^7 + 2^7 + 9^7

---------------------------------------------------------------------
import java.util.*;

/*
Suppose n is a positive integer and has decimal expansion:

n = a_0 + a_1(10) + a_2(10^2) + ... + a_m(10^m)

This program finds all n satisfying the condition:

n = (a_0)^POWER + (a_1)^POWER + (a_2)^POWER + ... + (a_m)^POWER

Notation: Let DigitPowerSum(m) denote

(a_0)^POWER + (a_1)^POWER + (a_2)^POWER + ... + (a_m)^POWER
*/
public class DigitPower
{
private static final int POWER = 4;

private Vector digits;

// If n equals DigitPowerSum(m), display n.
public static void main(String av[])
{
DigitPower digitPower = new DigitPower();

// Upper bound increases as POWER increases.
final long upperBound = digitPower.upperLimit(POWER);

for (long n = 1; n < upperBound; n++)
if (n == digitPower.getSum(n))
digitPower.showSum(n);

System.out.println("\n\nEnd of calculations");
}

// Find smallest positive integer n such that 10^n/(n + 1) > 9^n.
// Return 10^n.
private long upperLimit(int power)
{
int n;

final long upperBound = exponentiate(9, power);

for (n = 1; exponentiate(10, n) / (n + 1) <= upperBound; n++)
;

return exponentiate(10, n);
}

// Determine DigitPowerSum(m).
private long getSum(long n)
{
long sum = 0;

digits = getDigits(n);

for (Iterator i = digits.listIterator(); i.hasNext(); )
sum += exponentiate(((Long) i.next()).intValue(), POWER);

return sum;
}

// Store n's digits from right to left.
private Vector getDigits(long n)
{
Vector vector = new Vector();

for ( ; n > 0; n /= 10)
vector.add(new Long((n % 10)));

return vector;
}

// Calculate base raised to power exponent.
private long exponentiate(int base, int exponent)
{
long result = base;

for (int i = 1; i < exponent; i++)
result *= base;

return result;
}

// Show n and DigitPowerSum(m).
private void showSum(long n)
{
System.out.print(n + " = ");

for (int i = digits.size() - 1; i >= 0; i--)
System.out.print(((Long) digits.elementAt(i)).intValue() +
"^" + POWER + ((i == 0) ? "\n" : " + "));
}
}
-------------------------------------------------------------------

 

Are you Confused ?

Do you need assistance?

 

Let our Experts Help you:         

 
Copyright @Mathyards 2003-2004