in reply to Re: Simple arithmetic?
in thread Simple arithmetic?

Too late, forget about it...

Exactly, and one can also utilize the fact that 4096 is a power of 2:

$lcm = $r * 4096; $lcm /= 2 until $lcm % 8192; $c = int( $s/$lcm) * $lcm;

UPDATE: 7 hours of sleep later, here is what I wanted to say, but Anonymous Monk has posted it already in node 1119206.

use strict; use warnings; my $s = 3221225472; my $r = 5007; my $lcm = $r; my $m = 0; $lcm/=2 while 12>$m++ and !($lcm%2); $lcm *= 4096; my $c = int( $s/$lcm ) * $lcm; print "$c\n";

Replies are listed 'Best First'.
Re^3: Simple arithmetic?
by BrowserUk (Patriarch) on Mar 08, 2015 at 12:20 UTC
    and one can also utilize the fact that 4096 is a power of 2

    That's a really useful insight. It makes deriving the lcm substantially more efficient; especially for large values of S combined with R=prime. Thank you.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked