in reply to Simple arithmetic?
Using bog standard LCM:
my @T = ( [2147483648, 12, 4096], [3221225472, 5007, 4096], [4096, 4096, 4096], [8192, 8192, 4096], [15000, 8192, 4096], [17000, 8192, 4096], [17000, 10, 4096], ); sub gcd { !$_[1] ? $_[0] : gcd($_[1], $_[0] % $_[1]) } sub lcm { $_[0] * $_[1] / gcd($_[0], $_[1]) } for (@T) { my ($S, $R, $P) = @$_; my $N = $S - $S % lcm($R, $P); print "@$_: $N\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple arithmetic?
by BrowserUk (Patriarch) on Mar 08, 2015 at 12:29 UTC |