## A Diophantine equation related to happy bases

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

LucasBrown
Posts: 299
Joined: Thu Apr 15, 2010 2:57 am UTC
Location: Poway, CA

### A Diophantine equation related to happy bases

In a thread in the coding section, notzeb stated with incomplete proof that there is a number n>1 with happyb(n) = n if and only if b2+1 is composite, where happyb(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 happyb(n) = n must satisfy n < 3*(b-1)2, since for all n greater than that, happyb(n) < n; notzeb implicitly makes the stronger claim that n<b2 by representing it in base b as xyb. He then uses this to rewrite happyb(n) = n as b2+1 = (b-2x)2 + (2y-1)2 and concludes by claiming that b2+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 claimsfrom itertools import countfrom wherever import isprimefor 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`
Last edited by LucasBrown on Sun Jun 21, 2015 9:57 pm UTC, edited 1 time in total.

somehow
Posts: 99
Joined: Wed Aug 14, 2013 8:31 pm UTC

### Re: A Diophantine equation related to happy bases

I think I'm misunderstanding the statement of the question, because it seems to me that there are some easy counterexamples to the last claim: 5 = 4 + 1 and 17 = 16 + 1, for example, can be written as the sum of a square and an odd square, yet both are prime. What am I missing?
Xenomortis wrote:O(n2) takes on new meaning when trying to find pairs of socks in the morning.

LucasBrown
Posts: 299
Joined: Thu Apr 15, 2010 2:57 am UTC
Location: Poway, CA

### Re: A Diophantine equation related to happy bases

I should have included the clause "in a nontrivial way" in the original claim. I'll edit that now.

>-)
Posts: 527
Joined: Tue Apr 24, 2012 1:10 am UTC

### Re: A Diophantine equation related to happy bases

by https://en.m.wikipedia.org/wiki/Fermat' ... wo_squares we know any counter example has b^2+1 = 1 mod 4.

by http://mathworld.wolfram.com/SumofSquaresFunction.html we know the number of ways we can write a 1 mod 4 prime as a sum of squares is 1, and since 1+b^2 works, there are no nomtrivial counter examples