feat(maths::solver): prime opti
This commit is contained in:
parent
75c1d0712b
commit
4ba6a65a71
|
@ -46,7 +46,7 @@ fn simplify_sqrt(mut n: i128) -> (i128, i128) {
|
|||
let mut prime_factors = vec![];
|
||||
let mut prime = 3;
|
||||
println!("stuck {n}");
|
||||
while n != 1 {
|
||||
while n != 1 && prime * prime < n {
|
||||
if n % (prime - 1) == 0 {
|
||||
println!("stuck {n} {}", prime - 1);
|
||||
prime_factors.push(prime - 1);
|
||||
|
@ -170,7 +170,7 @@ fn get_strings(left_part: Rational, sqrt_delta: MySqrt) -> (String, String, Stri
|
|||
string_b = format!("{} + {string}", -a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
let len = std::cmp::max(string_a.len(), format!("{d}").len()) + 2;
|
||||
let len_b = std::cmp::max(string_b.len(), format!("{d}").len()) + 2;
|
||||
|
||||
|
@ -238,7 +238,7 @@ fn degree_two_complex(a: GaussianRational, b: GaussianRational, c: GaussianRatio
|
|||
|
||||
2362 / 473 + sqrt(7896511271) \ 49 / -473 + sqrt(7896511271) \
|
||||
---- + sqrt | ------------------------ | + -- i sign sqrt | ------------------------- | i
|
||||
32 \ 45150 / 13 \ 45150 /
|
||||
32 \ 45150 / 13 \ 45150 /
|
||||
|
||||
*/
|
||||
|
||||
|
@ -299,7 +299,7 @@ fn degree_two_complex(a: GaussianRational, b: GaussianRational, c: GaussianRatio
|
|||
let string2 = format!("{} + sqrt | {s2} | + {} i {sign} sqrt | {s5} | i", "-".repeat(b_real_len), "-".repeat(b_imag_len));
|
||||
let string3 = format!("{}{}{} \\ {s3} / {}{}{} \\ {s6} / ", " ".repeat(space3 / 2), b.real.denominator, " ".repeat(space3 / 2 + space3 % 2), " ".repeat(space4 / 2), b.imaginary.denominator, " ".repeat(space4 / 2 + space4 % 2));
|
||||
*/
|
||||
|
||||
|
||||
println!("{string1}");
|
||||
println!("{string2}");
|
||||
println!("{string3}");
|
||||
|
@ -362,7 +362,7 @@ fn print_degree_two_real(left_part: Rational, sqrt_delta: MySqrt, imaginary: boo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let len = std::cmp::max(string.chars().count(), format!("{d}").len()) + 2;
|
||||
|
||||
println!("{a} {b} {c} {d}");
|
||||
|
@ -400,7 +400,7 @@ fn degree_two_real(a: Rational, b: Rational, c: Rational) {
|
|||
}
|
||||
let mut sqrt_delta = sqrt(delta, a);
|
||||
let mut left_part = (-1 * b) / (2 * a);
|
||||
|
||||
|
||||
let tmp = left_part.denominator;
|
||||
|
||||
left_part.denominator *= sqrt_delta.denominator;
|
||||
|
@ -455,19 +455,19 @@ pub fn solve(mut equation: Vec<GaussianRational>) -> Vec<GaussianRational> {
|
|||
|
||||
2362 / 473 + sqrt(7896511271) \ 49 / -473 + sqrt(7896511271) \
|
||||
---- + sqrt | ------------------------ | + -- i sign sqrt | ------------------------- | i
|
||||
32 \ 45150 / 13 \ 45150 /
|
||||
32 \ 45150 / 13 \ 45150 /
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
/
|
||||
sqrt |
|
||||
sqrt |
|
||||
\
|
||||
|
||||
|
||||
/ 473 + sqrt(7896511271) \ / -473 + sqrt(7896511271) \
|
||||
2362 + 37 * sqrt | ------------------------ | + 46 * sqrt | ------------------------- |
|
||||
\ 45150 / \ 45150 /
|
||||
\ 45150 / \ 45150 /
|
||||
|
||||
--------------------------------------------------------------------------------------------- +
|
||||
|
||||
|
@ -480,4 +480,4 @@ sqrt |
|
|||
--------------------------------------------------------------------------------------------- i
|
||||
|
||||
21615671563
|
||||
*/
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue