library_checker/math/
sqrt_mod.rs1#[doc(no_inline)]
2pub use competitive::num::mint_basic::DynMIntU32;
3use competitive::prelude::*;
4
5#[verify::library_checker("sqrt_mod")]
6pub fn sqrt_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, q, yp: [(u32, u32)]);
10 for (y, p) in yp.take(q) {
11 DynMIntU32::set_mod(p);
12 if let Some(x) = DynMIntU32::from(y).sqrt() {
13 writeln!(writer, "{}", x).ok();
14 } else {
15 writeln!(writer, "-1").ok();
16 }
17 }
18}