HP Forums

Full Version: (12C) Sums of Two Squares
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Which whole numbers are expressible as sums of two (integer) squares?

This program solve the Sums of Two Squares. [ X^2 + Y^2 = N ]

Given N program will find pair of X,Y that equal to N

where X ≤ Y

----------------------------------------------------------

Procedure:

1.) N [R/S] display X [X<>Y] Y continue [R/S] if it is more than one solution and continue until steps 2.) shown mean finish.

2.) N [R/S] display 0.000000000 then 0.00 indicate that "No Solution"

----------------------------------------------------------

Example:

X^2 + Y^2 = 41

N = 41

41 [R/S] 4 [X<>Y] 5 [R/S] "0.000000000" 0.00

Answer: X = 4 and Y = 5
----------------------------------------------------------
X^2 + Y^2 = 76789

N = 76789

76789 [R/S] 135 [X<>Y] 242
[R/S] 150 [X<>Y] 233
[R/S] "0.000000000" 0.00

Answer:
X = 135 and Y = 242
X = 150 and Y = 233
-----------------------------------------------------------
Program:
Code:
 
01 STO 3
02 √X
03 INTG
04 STO 0
05 RCL 3
06  2
07  ÷
08 √X
09 STO 1
10 RCL 0
11 RCL 1
12 X≤Y
13 GTO 23
14 RCL 1
15 FRAC
16 X=0
17 GTO 10
18 CLx
19 FIX 9
20 PSE
21 FIX 2
22 GTO 00
23 RCL 3
24 RCL 0
25 ENTER
26  x
27  -
28 √X
29 ENTER
30 INTG
31 X<>Y
32 X≤Y
33 GTO 39
34 RCL 0
35  1
36  -
37 STO 0
38 GTO 10
39 RCL 0
40 X<>Y
41 R/S
42 GTO 34

Remark: Try this on 12C Emulator: N = 9876543210

Gamo
Reference URL's