All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Excellent numbers (Posted on 2017-04-08) Difficulty: 3 of 5
An excellent number n has an even number of digits and, if you split the number into the front half a and the back half b, then b^2 − a^2 = n.
For example, 3468 = 68^2 − 34^2.
The only two-digit excellent number is 48 and the only four-digit
excellent number is 3468.

There are eight six-digit excellent numbers.

List them.

Bonus: List all 10-digit excellent numbers.

Source: Project Euler.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution 12 digit excellence | Comment 2 of 3 |
I saw Charlie's solution and immediately thought that there had to be a more effective way to find these numbers without trying every single even digit number like he did.

And of course there is an easier way to search.  But first a little math to lay some groundwork.

Let n be 2k digits long.  then n = b^2 - a^2 and n = a*10^k + b.  Equating these two expressions for n and rearranging yields (2b-1)^2 = 4a*(a+10^k)+1.  Searching for values of a which make the right hand side a perfect square will be exponentially faster than a simple brute force search.

This code is for UBASIC
   10   for K=1 to 6
   20   Amax=10^K
   30   print Amax
   40   Amin=Amax\10+1
   50   for A=Amin to Amax
   60   X=4*A*(Amax+A)+1
   70   R=isqrt(X)
   80   Test=X-R*R
   90   if Test>0 then 120
  100   B=(R+1)\2
  105   if B>Amax then 120
  110   print A;B,
  120   next A
  130   print
  140   next K
This finds the following values (after a little formatting cleanup):
2 digits: 48

4 digits: 3468

6 digits: 140400, 190476, 216513, 300625, 334668, 416768, 484848, 530901

8 digits: 16604400, 33346668, 59809776

10 digits: 3333466668, 4848484848, 4989086476

12 digits: 101420334255, 181090462476, 238580543600, 243970550901, 268234583253, 274016590848, 320166650133, 333334666668, 346834683468, 400084748433, 440750796876, 502016868353, 569466945388

UBASIC is relatively slow, especially when being interpreted in DOSBOX so I chose not to try for 14 digit excellent numbers.

  Posted by Brian Smith on 2017-04-08 21:43:59
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information