Skip to content

Commit ea5d12b

Browse files
committed
ModIntのバグの修正等をしました
1 parent c0c653f commit ea5d12b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.DS_Store

12 KB
Binary file not shown.

ModInt/.DS_Store

6 KB
Binary file not shown.

ModInt/ModInt.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)