Casio fx-3650P - Inverse Calculation - 80 bytes Name Inverse Calculation Versions 0.1 Author Salvatore Fresta aka Drosophila Website http://www.salvatorefresta.net Contact salvatorefresta [at] gmail [dot] com Date 2011-01-15 X. INDEX I. DESCRIPTION II. COMMANDS USED III. CODE I. DESCRIPTION _______________ Casio fx-3650P is a programmable scientific calculator manufactured by Casio Computer Co., Ltd In this text I release a software able to calculate the inverse of a number in Zn for the Casio fx-3650P. Usage: A: number 1 B: number 2 Result: Inverse of A in Z(B) Inverse: C*A = 1 mod B Return values: C (the inverse) on success. 0 on error. I. COMMANDS USED ________________ Goto : Unconditional jump, jump to label. Lbl : Label, jump destination. ? : Operator input command, used when user's input is required. -> : Assign to variable command, to assign the value before it to the variable after it. => : Conditional jump, jump when conditions are met. >= : Relational operator. != : Relational operator. (>) : Output command, output the value. http://en.wikipedia.org/wiki/Casio_fx-3650P#Program III. CODE _________ The following is the code: Lbl 0: ?->A: ?->B: 0->C: 0->D: Lbl 1: C+1->C: C>=B => Goto 2: (C*A)/B-.5: Fix 0: Rnd: (C*A-BAns)->D: D!=1 => Goto 1: C (>) Goto 0: Lbl 2: 0 (>) Goto 0 The following is a C rappresentation of the previous software: #include void main() { int A, B, C, D; Lbl0: printf("\n A: "); scanf("%d", &A); printf("\n B: "); scanf("%d", &B); C=D=0; Lbl1: C=C+1; if(C >= B) goto Lbl2; D = (C*A) % B; if(D != 1) goto Lbl1; /* Inverse found successful */ printf("\n %d\n\n", C); goto Lbl0; Lbl2: /* Inverse not found */ printf("\n 0\n\n"); goto Lbl0; }