diff --git a/src/bin/08_revisit_everything.rs b/src/bin/08_revisit_everything.rs index c10f810..8f83460 100644 --- a/src/bin/08_revisit_everything.rs +++ b/src/bin/08_revisit_everything.rs @@ -1,10 +1,9 @@ #![allow(dead_code)] -use std::str::FromStr; use std::sync::LazyLock; +use lib::submit_with_name; +use rug::ops::DivRounding; use rug::Integer; -use rug::ops::{DivRounding, Pow}; -use lib::compute_async; - +use std::str::FromStr; // You can change the color of your name without changing your name. static M: LazyLock> = LazyLock::new(|| vec![ @@ -53,31 +52,35 @@ static M: LazyLock> = LazyLock::new(|| vec![ ]); static E: LazyLock = LazyLock::new(|| Integer::from(65537)); -static E_100: LazyLock = LazyLock::new(|| Integer::from(65537).pow(100)); -const N: u128 = 1000000000073185001u128; -const X: LazyLock = LazyLock::new(|| Integer::from_str("674404660282415099554286008259705897519728869877764551165256987500863620745793154396934476537394982658025146065927801862469915739446118680825670854157276563716625217760696826462684682154873582522786834148305185591910769146737370100544900325").unwrap()); +/// the first prime factor of [`M[30]`](M) +static P: LazyLock = LazyLock::new(|| Integer::from_str("2134638905903015345595412931439525422327695207079839833349799642610037970639957457078422305821013930668706217301787851463").unwrap()); +/// the second prime factor of [`M[30]`](M) +static Q: LazyLock = LazyLock::new(|| Integer::from_str("2134638905903015345595412931439525422327695207079839833349799642610037970639957457078422305821013930668706217301787851473").unwrap()); +/// [`φ(M[30])`](M) where `φ` is Euler's totient function +static PHI: LazyLock = 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() { + 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 w: usize = X.clone().modulo(&truth).try_into().unwrap(); - println!("w = {w}"); + let k = Integer::from(LIMIT - N) * 100; + let e = E.clone().pow_mod(&k, &PHI).unwrap(); - compute_async(move |tx| { - let mut n = N; - let y = X.clone().div_floor(&truth); + let x = Integer::from_str(X).unwrap(); + let w: usize = x.clone().modulo(&truth).try_into().unwrap(); + assert_eq!(w, 30); - let mut temp = y.clone(); - loop { - for _ in 0..10_000 { - n += 1; - temp = temp.pow_mod(&E_100, &M[w]).unwrap(); - } + let mut y = x.clone().div_floor(&truth); + y = y.pow_mod(&e, &M[30]).unwrap(); - let mut res = temp.clone(); - res *= &truth; - res += w; - tx.send((n, res)).unwrap(); - } - }); + let x: Integer = y * 42 + w; + println!("x = {x}\nn = {LIMIT}"); + submit_with_name(NAME, LIMIT, x).unwrap(); } \ No newline at end of file