_{b}(n) = n if and only if b

^{2}+1 is composite, where happy

_{b}(n) is the sum of the squares of n's digits when written in base b.

It is fairly simple to show that any solution to happy

_{b}(n) = n must satisfy n < 3*(b-1)

^{2}, since for all n greater than that, happy

_{b}(n) < n; notzeb implicitly makes the stronger claim that n<b

^{2}by representing it in base b as xy

_{b}. He then uses this to rewrite happy

_{b}(n) = n as b

^{2}+1 = (b-2x)

^{2}+ (2y-1)

^{2}and concludes by claiming that b

^{2}+1 can be written as a square plus an odd square in a nontrivial way* if and only if it's composite.

I have verified notzeb's claims via Python script for all b<2000, but this of course doesn't constitute proof for all b. Can anyone provide a proof of his claims?

Code: Select all

`# Verification of the claims`

from itertools import count

from wherever import isprime

for b in count(1):

p = isprime(b**2+1)

print b, b**2+1, "prime\t" if p else "\t",

q = True

for n in xrange(2, 3 * (b-1)**2):

xy, z = divmod(n, b)

x, y = divmod(xy, b)

assert n == (x*b + y)*b + z

if n == x**2 + y**2 + z**2:

print n,

if n > b**2: assert False, n

q = False

print

assert p == q, b