line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::ModInt::GF3; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
774
|
use 5.006; |
|
4
|
|
|
|
|
16
|
|
4
|
4
|
|
|
4
|
|
27
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
109
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
162
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ----- object definition ----- |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Math::ModInt::GF3=ARRAY(...) |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# .......... index .......... # .......... value .......... |
12
|
4
|
|
|
4
|
|
70
|
use constant F_RESIDUE => 0; # residue r, 0 .. 2 |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
298
|
|
13
|
4
|
|
|
4
|
|
25
|
use constant NFIELDS => 1; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
350
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ----- class data ----- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
4
|
|
|
4
|
|
40
|
require Math::ModInt; |
19
|
4
|
|
|
|
|
102
|
our @ISA = qw(Math::ModInt); |
20
|
4
|
|
|
|
|
2482
|
our $VERSION = '0.013'; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my @base = map { bless [$_] } 0..2; # singletons |
24
|
|
|
|
|
|
|
my @sgn = (0, 1, -1); |
25
|
|
|
|
|
|
|
my @neg = @base[0, 2, 1]; |
26
|
|
|
|
|
|
|
my @add = (\@base, [@base[1, 2, 0]], [@base[2, 0, 1]]); |
27
|
|
|
|
|
|
|
my @sub = (\@neg, [@base[1, 0, 2]], [@base[2, 1, 0]]); |
28
|
|
|
|
|
|
|
my @mul = ([@base[0, 0, 0]], \@base, \@neg ); |
29
|
|
|
|
|
|
|
my @pow = ( |
30
|
|
|
|
|
|
|
sub { $_[0] < 0? Math::ModInt->undefined: $base[!$_[0]] }, |
31
|
|
|
|
|
|
|
sub { $base[ 1] }, |
32
|
|
|
|
|
|
|
sub { $base[$_[0] % 2 + 1] }, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
*centered_residue = \&signed_residue; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# ----- private methods ----- |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
|
188
|
sub _NEG { $neg[$_[0]->[F_RESIDUE]] } |
40
|
9
|
|
|
9
|
|
22
|
sub _ADD { $add[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
41
|
9
|
|
|
9
|
|
22
|
sub _SUB { $sub[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
42
|
9
|
|
|
9
|
|
20
|
sub _MUL { $mul[$_[0]->[F_RESIDUE]]->[$_[1]->[F_RESIDUE]] } |
43
|
18
|
|
|
18
|
|
41
|
sub _POW { $pow[$_[0]->[F_RESIDUE]]->($_[1]) } |
44
|
3
|
100
|
|
3
|
|
11
|
sub _INV { $_[0]->[F_RESIDUE]? $_[0]: Math::ModInt->undefined } |
45
|
25
|
|
|
25
|
|
67
|
sub _NEW { $base[$_[1] % 3] } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _DIV { |
48
|
9
|
|
|
9
|
|
25
|
my $this = $_[0]->[F_RESIDUE]; |
49
|
9
|
|
|
|
|
13
|
my $that = $_[1]->[F_RESIDUE]; |
50
|
9
|
100
|
|
|
|
22
|
return $that? $mul[$this]->[$that]: Math::ModInt->undefined; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
150
|
|
|
150
|
1
|
442
|
sub residue { $_[0]->[F_RESIDUE] } |
54
|
6
|
|
|
6
|
1
|
147
|
sub signed_residue { $sgn[$_[0]->[F_RESIDUE]] } |
55
|
231
|
|
|
231
|
1
|
540
|
sub modulus { 3 } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |