結果
問題 | No.2576 LCM Pattern |
ユーザー | ikd |
提出日時 | 2023-12-04 13:50:25 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 3,789 bytes |
コンパイル時間 | 18,545 ms |
コンパイル使用メモリ | 378,332 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 22:57:38 |
合計ジャッジ時間 | 12,658 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
5,248 KB |
testcase_01 | AC | 0 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 0 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 0 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 0 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
ソースコード
use std::io; use scanner::Scanner; fn mpow(a: u64, x: u64, m: u64) -> u64 { if x == 0 { 1 % m } else if x % 2 == 0 { mpow(a * a % m, x / 2, m) } else { a * mpow(a, x - 1, m) % m } } fn main() { let mut scanner = Scanner::from(io::stdin().lock()); let (n, m) = scan!((u64, u64), <~ scanner); let mut m = m; let mut factorize = Vec::new(); for p in 2.. { if m == 1 { break; } if m < p * p { assert!(m >= p); factorize.push((m, 1)); break; } let mut e = 0; while m % p == 0 { m /= p; e += 1; } if e >= 1 { factorize.push((p, e)); } } const MOD: u64 = 998244353; let mut ans = 1; for (_, e) in factorize { ans *= (MOD + mpow(e + 1, n, MOD) - mpow(e, n, MOD)) % MOD; ans %= MOD; } println!("{}", ans); } // ✂ --- scanner --- ✂ #[allow(unused)] mod scanner { use std::fmt; use std::io; use std::str; pub struct Scanner<R> { r: R, l: String, i: usize, } impl<R> Scanner<R> where R: io::BufRead, { pub fn new(reader: R) -> Self { Self { r: reader, l: String::new(), i: 0, } } pub fn scan<T>(&mut self) -> T where T: str::FromStr, T::Err: fmt::Debug, { self.skip_blanks(); assert!(self.i < self.l.len()); // remain some character assert_ne!(&self.l[self.i..=self.i], " "); let rest = &self.l[self.i..]; let len = rest .find(|ch| char::is_ascii_whitespace(&ch)) .unwrap_or_else(|| rest.len()); // parse self.l[self.i..(self.i + len)] let val = rest[..len] .parse() .unwrap_or_else(|e| panic!("{:?}, attempt to read `{}`", e, rest)); self.i += len; val } pub fn scan_vec<T>(&mut self, n: usize) -> Vec<T> where T: str::FromStr, T::Err: fmt::Debug, { (0..n).map(|_| self.scan()).collect::<Vec<_>>() } fn skip_blanks(&mut self) { loop { match self.l[self.i..].find(|ch| !char::is_ascii_whitespace(&ch)) { Some(j) => { self.i += j; break; } None => { self.l.clear(); // clear buffer let num_bytes = self .r .read_line(&mut self.l) .unwrap_or_else(|_| panic!("invalid UTF-8")); assert!(num_bytes > 0, "reached EOF :("); self.i = 0; } } } } } impl<'a> From<&'a str> for Scanner<&'a [u8]> { fn from(s: &'a str) -> Self { Self::new(s.as_bytes()) } } impl<'a> From<io::StdinLock<'a>> for Scanner<io::BufReader<io::StdinLock<'a>>> { fn from(stdin: io::StdinLock<'a>) -> Self { Self::new(io::BufReader::new(stdin)) } } #[macro_export] macro_rules! scan { (( $($t: ty),+ ), <~ $scanner: expr) => { ( $(scan!($t, <~ $scanner)),+ ) }; ([ $t: tt; $n: expr ], <~ $scanner: expr) => { (0..$n).map(|_| scan!($t, <~ $scanner)).collect::<Vec<_>>() }; ($t: ty, <~ $scanner: expr) => { $scanner.scan::<$t>() }; } } // ✂ --- scanner --- ✂