Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,24 +1,22 @@
import std.stdio, std.bigint;
import std.stdio, std.bigint, std.math;
T lcm(T)(/*in*/ T m, /*in*/ T n) /*pure nothrow*/ {
if (m == 0) return m;
if (n == 0) return n;
T r = (m * n) / gcd(m, n);
//return abs(r);
return (r < 0) ? -r : r;
}
T gcd(T)(/*in*/ T a, /*in*/ T b) /*pure nothrow*/ {
while (b != 0) {
auto t = b;
T gcd(T)(T a, T b) pure /*nothrow*/ {
while (b) {
immutable t = b;
b = a % b;
a = t;
}
return a;
}
void main() {
writeln(lcm(12, 18));
writeln(lcm(BigInt("2562047788015215500854906332309589561"),
BigInt("6795454494268282920431565661684282819")));
T lcm(T)(T m, T n) pure /*nothrow*/ {
if (m == 0) return m;
if (n == 0) return n;
return abs((m * n) / gcd(m, n));
}
void main() {
lcm(12, 18).writeln;
lcm("2562047788015215500854906332309589561".BigInt,
"6795454494268282920431565661684282819".BigInt).writeln;
}