Skip to content

Instantly share code, notes, and snippets.

@m1el
Last active August 29, 2015 14:20
Show Gist options
  • Save m1el/4a7e45b8bbd70640265e to your computer and use it in GitHub Desktop.
Save m1el/4a7e45b8bbd70640265e to your computer and use it in GitHub Desktop.
N_NIMCALL(NI64, gcd_92056)(NI64 ia, NI64 ib) {
NI64 result;
NI64 a;
NI64 b;
nimfr("gcd", "p005.nim")
{ result = 0;
nimln(3, "p005.nim");
a = ia;
nimln(4, "p005.nim");
b = ib;
{
nimln(5, "p005.nim");
while (1) {
NI64 tmp;
NI64 TMP140;
if (!(IL64(0) < b)) goto LA2;
nimln(6, "p005.nim");
tmp = b;
nimln(7, "p005.nim");
TMP140 = modInt64(a, b);
b = (NI64)(TMP140);
nimln(8, "p005.nim");
a = tmp;
} LA2: ;
}
nimln(9, "p005.nim");
result = a;
goto BeforeRet;
}BeforeRet: ;
popFrame();
return result;
}
N_NIMCALL(NI64, lcm_92047)(NI64 a_92051, NI64 b_92053) {
NI64 result;
NI64 TMP139;
NI64 LOC1;
NI64 TMP141;
nimfr("lcm", "p005.nim")
{ result = 0;
nimln(12, "p005.nim");
TMP139 = mulInt64(a_92051, b_92053);
LOC1 = 0;
LOC1 = gcd_92056(a_92051, b_92053);
TMP141 = divInt64((NI64)(TMP139), LOC1);
result = (NI64)(TMP141);
goto BeforeRet;
}BeforeRet: ;
popFrame();
return result;
}
proc gcd[T](ia,ib: T): T =
var
a = ia
b = ib
while b > 0:
a = a mod b
swap(a, b)
return a
proc lcm[T](a, b: T): T =
return (a * b) div gcd(a, b)
var res:int64 = 1
for i in 1..20:
res = lcm(res, i)
echo res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment