File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,14 @@ public ModInt create(long value) {
4343 private void prepareFactorial (int max ){
4444 factorial .ensureCapacity (max +1 );
4545 if (factorial .size ()==0 ) factorial .add (1 );
46- for (int i =factorial .size (); i <=max ; i ++){
47- factorial .add (ma .mul (factorial .get (i -1 ), i ));
46+ if (usesMontgomery ) {
47+ for (int i =factorial .size (); i <=max ; i ++){
48+ factorial .add (ma .mul (factorial .get (i -1 ), maMontgomery .generate (i )));
49+ }
50+ } else {
51+ for (int i =factorial .size (); i <=max ; i ++){
52+ factorial .add (ma .mul (factorial .get (i -1 ), i ));
53+ }
4854 }
4955 }
5056
@@ -77,8 +83,8 @@ public int mod() {
7783 return mod ;
7884 }
7985 public int value () {
80- if (ma instanceof ModArithmetic . ModArithmeticMontgomery ) {
81- return (( ModArithmetic . ModArithmeticMontgomery ) ma ) .reduce (value );
86+ if (usesMontgomery ) {
87+ return maMontgomery .reduce (value );
8288 }
8389 return value ;
8490 }
You can’t perform that action at this time.
0 commit comments