結果

問題 No.1396 Giri
ユーザー StrorkisStrorkis
提出日時 2021-02-15 16:29:57
言語 Rust
(1.77.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,419 bytes
コンパイル時間 11,981 ms
コンパイル使用メモリ 405,432 KB
最終ジャッジ日時 2024-04-27 03:35:59
合計ジャッジ時間 12,611 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error: format argument must be a string literal
  --> src/main.rs:17:34
   |
17 |                 Err(e) => panic!(e), 
   |                                  ^
   |
help: you might be missing a string literal to format with
   |
17 |                 Err(e) => panic!("{}", e), 
   |                                  +++++

error: could not compile `main` (bin "main") due to 1 previous error

ソースコード

diff #

mod io {
    #[macro_export]
    macro_rules! scan {
        ($r:expr, [$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($r, $t)).collect::<Vec<_>>());
        ($r:expr, ($($t:tt),*)) => (($(scan!($r, $t)),*));
        ($r:expr, [u8]) => (io::scan($r));
        ($r:expr, String) => (io::scan($r).into_iter().map(char::from).collect::<String>());
        ($r:expr, $t:ty) => (scan!($r, String).parse::<$t>().unwrap());
    }

    pub fn scan<R: std::io::BufRead>(r: &mut R) -> Vec<u8> {
        let mut res = Vec::new();
        loop {
            let buf = match r.fill_buf() {
                Ok(buf) => buf,
                Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
                Err(e) => panic!(e), 
            };
            let (done, used) = match buf.iter().position(u8::is_ascii_whitespace) {
                Some(i) => {
                    res.extend_from_slice(&buf[..i]);
                    (res.len() > 0, i + 1)
                }
                None => {
                    res.extend_from_slice(buf);
                    (buf.is_empty(), buf.len())
                }
            };
            r.consume(used);
            if done { return res; }
        }
    }
}

#[allow(dead_code)]
mod mod_int {
    #[derive(Clone, Copy)]
    pub struct ModInt(pub i64);

    impl ModInt {
        const MOD: i64 = 998_244_353;

        pub fn new(x: i64) -> ModInt {
            Self(x % Self::MOD)
        }
    }

    impl std::ops::Add for ModInt {
        type Output = Self;

        fn add(self, other: Self) -> Self {
            let x = self.0 + other.0;
            if x < Self::MOD { Self(x) } else { Self(x - Self::MOD) }
        }
    }

    impl std::ops::AddAssign for ModInt {
        fn add_assign(&mut self, other: Self) {
            *self = *self + other;
        }
    }

    impl std::ops::Sub for ModInt {
        type Output = Self;

        fn sub(self, other: Self) -> Self {
            if self.0 < other.0 {
                Self(self.0 + Self::MOD - other.0)
            } else {
                Self(self.0 - other.0)
            }
        }
    }

    impl std::ops::SubAssign for ModInt {
        fn sub_assign(&mut self, other: Self) {
            *self = *self - other;
        }
    }

    impl std::ops::Mul for ModInt {
        type Output = Self;

        fn mul(self, other: Self) -> Self {
            Self::new(self.0 * other.0)
        }
    }

    impl std::ops::MulAssign for ModInt {
        fn mul_assign(&mut self, other: Self) {
            *self = *self * other;
        }
    }

    impl std::fmt::Display for ModInt {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }

    impl From<usize> for ModInt {
        fn from(x: usize) -> Self {
            Self(x as i64)
        }
    }

    impl ModInt {
        pub fn pow<T: std::convert::TryInto<usize>>(mut self, n: T) -> Self {
            let mut n: usize = n.try_into().ok().unwrap();
            let mut res = Self(1);
            while n != 0 {
                if n & 1 != 0 {
                    res *= self;
                }
                self *= self;
                n >>= 1;
            }
            res
        }
        
        pub fn inv(self) -> Self {
            self.pow(Self::MOD - 2)
        }
    }
}

use mod_int::ModInt;

fn run<R: std::io::BufRead, W: std::io::Write>(reader: &mut R, writer: &mut W) {
    let n = scan!(reader, usize);

    let mut cnt = vec![0; n + 1];
    for mut x in 2..=n {
        for (i, cnt) in cnt.iter_mut().enumerate().skip(2) {
            if i * i > x { break; }
            let mut c = 0;
            while x % i == 0 {
                c += 1;
                x /= i;
            }
            *cnt = (*cnt).max(c);
        }
        if x > 1 {
            let val = &mut cnt[x];
            *val = (*val).max(1);
        }
    }

    let mut ans = ModInt(1);
    let mut flag = true;
    for (i, cnt) in cnt.iter_mut().enumerate().rev() {
        if flag && *cnt > 0 {
            *cnt = 0;
            flag = false;
        }
        ans *= ModInt::from(i).pow(*cnt)
    }
    writeln!(writer, "{}", ans).ok();
}
 
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());
    run(&mut reader, &mut writer);
}
0