/* longint.c */
#include "longint.h"
int main(void)
{
LINT a, b, c, d, x, y;
int r;
a = lset(56789L); lwrite("a", a);
b = lset(987654321L); lwrite("b", b);
c = lset(9999L); lwrite("c", c);
d = lset(2063254981L); lwrite("d", d);
putchar('\n');
x = ladd(a, b); lwrite("a + b", x);
x = ladd(b, c); lwrite("b + c", x);
x = ladd(c, a); lwrite("c + a", x);
putchar('\n');
printf("a:b=%d b:c=%d c:a=%d\n", lcmp(a, b), lcmp(b, c), lcmp(c, a));
x = lsub(a, b); lwrite("a - b", x);
x = lsub(b, c); lwrite("b - c", x);
x = lsub(c, a); lwrite("c - a", x);
putchar('\n');
x = smul(a, 10); lwrite("a * 10", x);
x = smul(b, 10); lwrite("b * 10", x);
x = smul(c, 10); lwrite("c * 10", x);
putchar('\n');
x = lmul(a, b); lwrite("a * b", x);
x = lmul(b, c); lwrite("b * c", x);
x = lmul(c, a); lwrite("c * a", x);
putchar('\n');
x = sdiv(a, 30, &r); lwrite("a / 30", x);
printf("residue = %d\n", r);
x = sdiv(b, 25, &r); lwrite("b / 25", x);
printf("residue = %d\n", r);
x = sdiv(c, 20, &r); lwrite("c / 20", x);
printf("residue = %d\n", r);
lup(&a, 3); lwrite("a = (a << 3)", a);
putchar('\n');
x = ldivide(b, a, &y); lwrite("b / a", x);
lwrite("residue", y);
x = ldivide(b, c, &y); lwrite("b / c", x);
lwrite("residue", y);
x = ldivide(a, c, &y); lwrite("a / c", x);
lwrite("residue", y);
x = ldivide(a, b, &y); lwrite("a / b", x);
lwrite("residue", y);
putchar('\n');
x = lsqrt(a); lwrite("sqrt(a)", x);
x = lsqrt(b); lwrite("sqrt(b)", x);
x = lsqrt(d); lwrite("sqrt(d)", x);
putchar('\n');
lwrite("a", a);
printf("a mod 789 = %d\n", smod(a, 789));
lwrite("b", b);
printf("b mod 789 = %d\n", smod(b, 789));
lwrite("c", c);
printf("c mod 789 = %d\n", smod(c, 789));
lwrite("d", d);
printf("d mod 789 = %d\n", smod(d, 789));
a = lset(8L); lwrite("a", a);
b = lset(26L); lwrite("b", b);
c = lset(55L); lwrite("n", c);
x = lpwrmod(a, b, c); lwrite("a ^ b (mod n)", x);
putchar('\n');
a = lset(23168L); lwrite("a", a);
b = lset(19L); lwrite("b", b);
c = lset(32655485L); lwrite("n", c);
x = lpwrmod(a, b, c); lwrite("a ^ b (mod n)", x);
putchar('\n');
a = lset(45623156L); lwrite("a", a);
b = lset(981356L); lwrite("b", b);
x = lgcd(a, b); lwrite("GCD(a,b)", x);
putchar('\n');
a = lset(10L);
b = lset(23L);
c = linv(a, b); lwrite("inv(10,23)", c);
putchar('\n');
a = lset(23L);
x = lpwr(a, 8); lwrite("23 ^ 8", x);
putchar('\n');
a = lset(15346L);
x = lsqr(a); lwrite("a ^ 2", x);
putchar('\n');
lwrite("a", a);
lwrite("x", x);
lswap(&a, &x);
printf("swap a <==> x\n");
lwrite("a", a);
lwrite("x", x);
putchar('\n');
x = lkaijo(449); printf("449! ≒ 3.85e+997 (スターリングの公式による)\n");
lwrite("449!",x);
putchar('\n');
x = lset(79L); lwrite("x:", x);
printf(" , Prime Check : %d\n", (r = lprime_chk(x)));
if(!r) lfactor(x);
x = lset(40353607L); lwrite("x:", x);
printf(" , Prime Check : %d\n", (r = lprime_chk(x)));
if(!r) lfactor(x);
x = lkaijo(10);
alinc(&x, 1); lwrite("x:", x);
printf(" , Prime Check : %d\n",(r = lprime_chk(x)));
x = lkaijo(30);
alinc(&x, 1); lwrite("x:", x);
printf(" , Prime Check : %d\n",(r = lprime_chk(x)));
return 1;
}
|