use rug::ops::DivRounding; use rug::Integer; use std::str::FromStr; const PHI: &str = "4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616565666555545842363207724851343853529903674824524238732001458342230627654145983386115997227846421784693186847971068054052064"; const M: &str = "4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616569935833357648393898915677206732580748330214938398411668157941515847730087263301030154072458063812554524260405671629754999"; const E: u64 = 65537; const LIMIT: u128 = 100_000_000_000_000_000_000; pub fn solve(n: u64, x: Integer) -> Result<(u128, Integer), u32> { let truth = Integer::from(42); let phi = Integer::from_str(PHI).unwrap(); let m = Integer::from_str(M).unwrap(); let k = Integer::from(LIMIT - n as u128) * 100; let e = Integer::from(E).pow_mod(&k, &phi).unwrap(); let w: u32 = x.clone().modulo(&truth).try_into().unwrap(); if w != 30 { return Err(w); } let mut y = x.clone().div_floor(&truth); y = y.pow_mod(&e, &m).unwrap(); let x: Integer = y * 42 + w; Ok((LIMIT, x)) }