Multiplicative order: Difference between revisions
m
→{{header|Raku}}: Modernize, speed up quite a bit (meh, goes from ~1/2 second to ~1/4 second)
Thundergnat (talk | contribs) m (→{{header|Raku}}: Modernize, speed up quite a bit (meh, goes from ~1/2 second to ~1/4 second)) |
|||
Line 1,834:
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>
sub mo-prime($a, $p, $e) {
my $m = $p ** $e;
my $t = ($p - 1) * ($p ** ($e - 1)); # = Phi($p**$e) where $p prime
my @qs = 1;
for
@qs = flat @qs.map(-> $q { (0..$f.value).map(-> $j { $q * $f.key ** $j }) });
}
@qs.sort.first
}
sub mo($a, $m) {
$a gcd $m == 1
[lcm] flat 1,
}
use Test;
for (10, 21, 25, 150, 1231, 123141, 34131) -> $n {
is ([*]
}
is mo(37, 1000), 100, 'mo(37,1000) == 100';
my $b = 10**20-1;
is mo(2, $b), 3748806900, 'mo(2,10**20-1) == 3748806900';
is mo(17, $b), 1499522760, 'mo(17,10**20-1) == 1499522760';
$b = 100001;
is mo(54, $b), 9090, 'mo(54,100001) == 9090';
|