|
|
1.1 ! root 1: #include "mprec.h" ! 2: ! 3: ! 4: /* ! 5: * Gcd sets the value of the mint pointed to by "c" to the greatest ! 6: * common divisor of the mints pointed to by "a" and "b". Note that ! 7: * no assumption made on the distinctness of "a", "b" and "c". ! 8: */ ! 9: ! 10: void ! 11: gcd(a, b, c) ! 12: register mint *a, *b, *c; ! 13: { ! 14: register mint *temp; ! 15: mint al, bl, quot; ! 16: ! 17: /* make local copyies of arguments */ ! 18: minit(&al); ! 19: mcopy(a, &al); ! 20: a = &al; ! 21: minit(&bl); ! 22: mcopy(b, &bl); ! 23: b = &bl; ! 24: ! 25: /* calculate gcd by Euclidean algorithm */ ! 26: minit("); ! 27: while (!zerop(b)) { ! 28: mdiv(a, b, ", a); ! 29: temp = a; ! 30: a = b; ! 31: b = temp; ! 32: } ! 33: ! 34: /* throw away garbage and return result */ ! 35: mpfree(quot.val); ! 36: mpfree(b->val); ! 37: mpfree(c->val); ! 38: *c = *a; ! 39: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.