[08_revisit_everything] add solution

Luckily M[30] is easily factorable as it is almost a perfect square.
This commit is contained in:
2025-09-16 20:48:31 +02:00
parent b2e43654c1
commit 5e37cfe883

View File

@@ -1,10 +1,9 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::str::FromStr;
use std::sync::LazyLock; use std::sync::LazyLock;
use lib::submit_with_name;
use rug::ops::DivRounding;
use rug::Integer; use rug::Integer;
use rug::ops::{DivRounding, Pow}; use std::str::FromStr;
use lib::compute_async;
// You can change the color of your name without changing your name. // You can change the color of your name without changing your name.
static M: LazyLock<Vec<Integer>> = LazyLock::new(|| vec![ static M: LazyLock<Vec<Integer>> = LazyLock::new(|| vec![
@@ -53,31 +52,35 @@ static M: LazyLock<Vec<Integer>> = LazyLock::new(|| vec![
]); ]);
static E: LazyLock<Integer> = LazyLock::new(|| Integer::from(65537)); static E: LazyLock<Integer> = LazyLock::new(|| Integer::from(65537));
static E_100: LazyLock<Integer> = LazyLock::new(|| Integer::from(65537).pow(100));
const N: u128 = 1000000000073185001u128; /// the first prime factor of [`M[30]`](M)
const X: LazyLock<Integer> = LazyLock::new(|| Integer::from_str("674404660282415099554286008259705897519728869877764551165256987500863620745793154396934476537394982658025146065927801862469915739446118680825670854157276563716625217760696826462684682154873582522786834148305185591910769146737370100544900325").unwrap()); static P: LazyLock<Integer> = LazyLock::new(|| Integer::from_str("2134638905903015345595412931439525422327695207079839833349799642610037970639957457078422305821013930668706217301787851463").unwrap());
/// the second prime factor of [`M[30]`](M)
static Q: LazyLock<Integer> = LazyLock::new(|| Integer::from_str("2134638905903015345595412931439525422327695207079839833349799642610037970639957457078422305821013930668706217301787851473").unwrap());
/// [`φ(M[30])`](M) where `φ` is Euler's totient function
static PHI: LazyLock<Integer> = LazyLock::new(|| Integer::from_str("4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616565666555545842363207724851343853529903674824524238732001458342230627654145983386115997227846421784693186847971068054052064").unwrap());
const LIMIT: u128 = 100_000_000_000_000_000_000;
const NAME: &str = " Jonah";
const N: u128 = 1000000000000000000;
const X: &str = "3595876711108608978";
fn main() { fn main() {
debug_assert_eq!(M[30].clone(), P.clone() * Q.clone());
debug_assert_eq!(PHI.clone(), (P.clone() - 1) * (Q.clone() - 1));
let truth = Integer::from(42); let truth = Integer::from(42);
let w: usize = X.clone().modulo(&truth).try_into().unwrap(); let k = Integer::from(LIMIT - N) * 100;
println!("w = {w}"); let e = E.clone().pow_mod(&k, &PHI).unwrap();
compute_async(move |tx| { let x = Integer::from_str(X).unwrap();
let mut n = N; let w: usize = x.clone().modulo(&truth).try_into().unwrap();
let y = X.clone().div_floor(&truth); assert_eq!(w, 30);
let mut temp = y.clone(); let mut y = x.clone().div_floor(&truth);
loop { y = y.pow_mod(&e, &M[30]).unwrap();
for _ in 0..10_000 {
n += 1;
temp = temp.pow_mod(&E_100, &M[w]).unwrap();
}
let mut res = temp.clone(); let x: Integer = y * 42 + w;
res *= &truth; println!("x = {x}\nn = {LIMIT}");
res += w; submit_with_name(NAME, LIMIT, x).unwrap();
tx.send((n, res)).unwrap();
}
});
} }