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

 Squares and Cubes (Posted on 2003-12-06)
What are the two smallest positive whole numbers the difference of whose squares is a cube and the difference of whose cubes is a square ?

 See The Solution Submitted by Ravi Raja Rating: 3.7500 (4 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 re: Nontrivial Implied | Comment 9 of 21 |
(In reply to Nontrivial Implied by Richard)

The program in two versions: Quick Basic and UBASIC:
DEFDBL A-Z
sum = 3
DO
FOR a = 1 TO (sum + 1) / 2 - 1
b = sum - a
diffSq = b * b - a * a
diffCu = b * b * b - a * a * a
cuRt = INT(diffSq ^ (1 / 3) + .5)
sqRt = INT(SQR(diffCu) + .5)
IF sqRt * sqRt = diffCu AND cuRt * cuRt * cuRt = diffSq THEN
PRINT a, b
ct = ct + 1: IF ct > 40 THEN END
END IF
NEXT
sum = sum + 1
LOOP

```
10   for Sum=3 to 30000000

15     Max=int((Sum+1)/2-1)

20    for A=1 to Max

30       B=Sum-A

40       DiffSq=B*B-A*A

50       DiffCu=B*B*B-A*A*A

60       CuRt=int(DiffSq^(1/3)+0.5)

70       SqRt=int(sqrt(DiffCu)+0.5)

80       if SqRt*SqRt=DiffCu and CuRt*CuRt*CuRt=DiffSq then

90       :print A,B

100    next

110   next

```

--------
UBASIC has additional precision available. It was stopped when sum was in the 5000+ range, and found only the two answers I posted. At these high numbers the cubing would get to the murky boundaries of the precision available to QuickBasic.
 Posted by Charlie on 2003-12-06 13:52:06

 Search: Search body:
Forums (1)
Random Problem
Site Statistics
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox: