05-30-2014, 06:31 PM

For input of a positive composite odd number the programme returns a factor. Fermat's method seeks to find two squares differing by the input as

n= x^2-y^2=(x+y)(x-y) & hey presto, two factors have been found.

1 LBL X

2 STO A

3 SQRTx

4 IP

5 2*REGX+1►X

6 SGN

7 STO Y

8 R↓

9 x^2

10 RCL- A

11 x=0?

12 GTO X024

13 RCL+ X

14 2

15 STO+ X

16 R↓

17 RCL- Y

18 2

19 STO+ Y

20 R↓

21 x>0?

22 GTO X017

23 GTO X011

24 RCL X

25 RCL- Y

26 2

27 ÷

28 RTN

n= x^2-y^2=(x+y)(x-y) & hey presto, two factors have been found.

1 LBL X

2 STO A

3 SQRTx

4 IP

5 2*REGX+1►X

6 SGN

7 STO Y

8 R↓

9 x^2

10 RCL- A

11 x=0?

12 GTO X024

13 RCL+ X

14 2

15 STO+ X

16 R↓

17 RCL- Y

18 2

19 STO+ Y

20 R↓

21 x>0?

22 GTO X017

23 GTO X011

24 RCL X

25 RCL- Y

26 2

27 ÷

28 RTN