Function discrete_logarithm

Source
pub fn discrete_logarithm(a: u64, b: u64, n: u64) -> Option<u64>
Expand description

a^x ≡ b (mod n)

Examples found in repository?
crates/library_checker/src/math/discrete_logarithm_mod.rs (line 11)
6pub fn discrete_logarithm_mod(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, t, query: [(u64, u64, u64)]);
10    for (x, y, m) in query.take(t) {
11        let ans = discrete_logarithm(x, y, m).map(|k| k as i64).unwrap_or(-1);
12        writeln!(writer, "{}", ans).ok();
13    }
14}