struct Linear<T>where
T: Signed,{
a: T,
b: T,
}Expand description
ax + b
Fields§
§a: T§b: TImplementations§
Source§impl<T> Linear<T>where
T: Signed,
impl<T> Linear<T>where
T: Signed,
Sourcefn new(a: T, b: T) -> Self
fn new(a: T, b: T) -> Self
Examples found in repository?
crates/competitive/src/math/linear_diophantine.rs (line 145)
133pub fn solve_linear_diophantine<T>(a: T, b: T, c: T) -> Option<LinearDiophantineSolution<T>>
134where
135 T: Signed,
136{
137 assert!(!a.is_zero(), "a must be non-zero");
138 assert!(!b.is_zero(), "b must be non-zero");
139 let ExtendedGcd { g, x: x0, y: y0 } = a.extgcd(b);
140 let g = g.signed();
141 let a = a / g;
142 let b = b / g;
143 if c.is_zero() {
144 return Some(LinearDiophantineSolution {
145 x: Linear::new(b, T::zero()),
146 y: Linear::new(-a, T::zero()),
147 k_range: (T::minimum(), T::maximum()),
148 });
149 }
150 if !(c % g).is_zero() {
151 return None;
152 }
153 let c = c / g;
154 let x = Linear::new(b, x0 * c);
155 let y = Linear::new(-a, y0 * c);
156 Some(LinearDiophantineSolution {
157 x,
158 y,
159 k_range: (T::minimum(), T::maximum()),
160 })
161}Trait Implementations§
impl<T> Copy for Linear<T>
Auto Trait Implementations§
impl<T> Freeze for Linear<T>where
T: Freeze,
impl<T> RefUnwindSafe for Linear<T>where
T: RefUnwindSafe,
impl<T> Send for Linear<T>where
T: Send,
impl<T> Sync for Linear<T>where
T: Sync,
impl<T> Unpin for Linear<T>where
T: Unpin,
impl<T> UnwindSafe for Linear<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more