# TITLE: Linear Congruence Solver # AUTHOR: Roy F.A. Maclean # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 28Nov1997, 6Jun1999, 18Jan2000, 3Jul2007 # MAKE: CASIO # MODEL: 9850 # SIZE: 207+90 # # NOTES: # Solves linear congruences of the form ax=b(mod m) for x. # Enter the values a,b,m and the solns will be displayed. # # Two program areas needed # # Prog "EUCSUB" inputs are X,Y.Outputs are X,A,C. # Where new X=GCD(old X,Y)=A(old X)+CY. @@ Program "LCONG" Lbl 0 "AX=B MOD M" "A"?->U:"B"?->V:"M"?->M U->X:M->Y Prog "E" If X=1 Then AV-M*Int (AV/M)->G G<0=>M+G->G G_ IfEnd X=1=>Goto 0 Frac (V/X)=0=>Goto 1 "NO SOLN" Goto 0 Lbl 1 U/X->I:V/X->J:M/X->K X->H:I->X:K->Y Prog "EUCSUB" AJ-K*Int (AJ/K)->G G<0=>G+K->G For 0->C To H-1 G+CK_ Next Goto 0 @@ Program "EUCSUB" 1->A~B:0->C~D Lbl 1 Int (X/Y) X-AnsY->R A-AnsD->E C-AnsB->F D->A:B->C:E->D F->B:Y->X:R->Y Y<>0=>Goto 1