Number Magic

Inspired by Anand Mohanram’s post on square-cube patterns.

Pattern 1: Square-Cube Differences

The differences between perfect cube and perfect square numbers follow an arithmetic progression with a common difference of 1. The pattern emerges from solving:

a³ + b² = (a+b)²

Which simplifies to:

b = a(a-1) / 2

Some examples:

a b a+b
2 1 3
3 3 6
4 6 10
5 10 15
10 45 55
45 990 1035

Java Implementation

public void findSquareCubeNumbers(int count) {
    for (int i = 1; i < count; i++) {
        int num = i * i * i;
        for (int j = 1; j < count; j++) {
            int sum = i + j;
            if (num + (j * j) == sum * sum) {
                System.out.println(i + "+" + j + "=" + sum);
            }
        }
    }
}

Pattern 2: Power Sequence

For numbers 1–10, if k satisfies k^n + k^(n+1) = (2k)^n, then (2k+1) satisfies the same condition for n+1.

Examples:

  • k=1, n=1: 1¹ + 1² = 2¹
  • k=3, n=2: 3² + 3³ = 6²
  • k=7, n=3: 7³ + 7⁴ = 14³
  • k=15, n=4: 15⁴ + 15⁵ = 30⁴

Java Implementation

public void findNextPowerNumbers(int powVal, int count) {
    double prevK = 0;
    for (double i = 1; i < powVal; i++) {
        double power = i + 1;
        for (double k = 1; k < count; k++) {
            double num = Math.pow(k, power);
            double num1 = Math.pow(k, i);
            double sum = 2 * k;
            double num3 = Math.pow(sum, i);
            if (num + num1 == num3) {
                System.out.println(
                    "(k= " + k + "((2*" + prevK + ")+1); n= " + i + ") "
                    + k + "^" + i + "+" + k + "^" + power + "=" + sum + "^" + i
                );
                prevK = k;
            }
        }
    }
}

See the follow-up post Numbers: Not Everything Is Magic where I derive why this pattern works and where the apparent magic disappears once you do the algebra.