A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
24
Task/Least-common-multiple/D/least-common-multiple.d
Normal file
24
Task/Least-common-multiple/D/least-common-multiple.d
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import std.stdio, std.bigint;
|
||||
|
||||
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;
|
||||
b = a % b;
|
||||
a = t;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln(lcm(12, 18));
|
||||
writeln(lcm(BigInt("2562047788015215500854906332309589561"),
|
||||
BigInt("6795454494268282920431565661684282819")));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue