From 79253529ea91e6a035671f434e4a759d9db31947 Mon Sep 17 00:00:00 2001 From: rsk0315 Date: Mon, 21 Aug 2023 19:12:06 +0900 Subject: [PATCH] fix --- crates/ds/bit_set/src/lib.rs | 2 +- crates/math/modint/src/lib.rs | 8 +++++--- static/nekolib/src/math.rs | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ds/bit_set/src/lib.rs b/crates/ds/bit_set/src/lib.rs index fef0f4a..473f405 100644 --- a/crates/ds/bit_set/src/lib.rs +++ b/crates/ds/bit_set/src/lib.rs @@ -63,7 +63,7 @@ impl BitSet { } #[must_use] - pub fn contains(&mut self, index: usize) -> bool { + pub fn contains(&self, index: usize) -> bool { check_bounds(index, self.capacity); let (wi, bi) = (index / WORD_SIZE, index % WORD_SIZE); diff --git a/crates/math/modint/src/lib.rs b/crates/math/modint/src/lib.rs index dafd4ec..afc394b 100644 --- a/crates/math/modint/src/lib.rs +++ b/crates/math/modint/src/lib.rs @@ -218,12 +218,13 @@ impl Barrett { fn mul(&self, a: u32, b: u32) -> u32 { let m = self.m.load(atomic::Ordering::SeqCst); - let im = self.m.load(atomic::Ordering::SeqCst); + let im = self.im.load(atomic::Ordering::SeqCst); let z = a as u64 * b as u64; let x = ((z as u128 * im as u128) >> 64) as u64; - let v = z.wrapping_sub(x.wrapping_mul(m as u64)) as u32; - if m <= v { v.wrapping_add(m) } else { v } + let y = x.wrapping_mul(m as u64); + let v = z.wrapping_sub(y) as u32; + v.wrapping_add(if z < y { m } else { 0 }) } } @@ -509,6 +510,7 @@ fn sanity_check() { type Md = DynamicModInt; Md::set_modulus(10); assert_eq!(Md::new(5) + Md::new(7), Md::new(2)); + assert_eq!(Md::new(3) * Md::new(4), Md::new(2)); Md::set_modulus(4); assert_eq!(Md::new(5) + Md::new(7), Md::new(0)); diff --git a/static/nekolib/src/math.rs b/static/nekolib/src/math.rs index e34908a..3243a4a 100644 --- a/static/nekolib/src/math.rs +++ b/static/nekolib/src/math.rs @@ -129,8 +129,8 @@ pub use mod_recip_table_::mod_recip_table_prime; pub use mod_tetration::ModTetration; #[doc(inline)] pub use modint::{ - Mod1000000007, Mod998244353, ModInt1000000007, ModInt998244353, ModIntBase, - Modulus, StaticModInt, + DefaultId, DynamicModInt, Mod1000000007, Mod998244353, ModInt1000000007, + ModInt998244353, ModIntBase, Modulus, StaticModInt, }; #[doc(inline)] pub use prime_pi_::prime_pi;