結果
問題 | No.2176 LRM Question 1 |
ユーザー |
|
提出日時 | 2023-02-25 18:47:20 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 3,271 bytes |
コンパイル時間 | 20,955 ms |
コンパイル使用メモリ | 379,532 KB |
実行使用メモリ | 9,832 KB |
最終ジャッジ日時 | 2024-09-13 14:28:05 |
合計ジャッジ時間 | 22,146 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#![allow(unused_imports, unused_macros)]use myu2::*;use std::cmp::*;use std::collections::*;use std::io::Read;fn main() {input! {l: usize,r: usize,m: usize,}let mut fact = vec![1; m + 10];for i in 1..m + 10 {fact[i] = (fact[i - 1] * i) % m;}let mut x = 1;for i in 1..l + 1 {if i > m + 1 {break;}x *= fact[i];x %= m;}let mut ans = x;for i in l + 1..r + 1 {if i > m + 1 {break;}x *= fact[i];x %= m;ans += x;ans %= m;}println!("{}", ans);}// lib// util#[macro_use]pub mod myu2 {// input#[macro_export]macro_rules! input { ($($r:tt)*) => { let mut bytes = std::io::Read::bytes(std::io::BufReader::new(std::io::stdin())); let mut next = move|is_word: bool| -> String{if is_word { bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() } else { bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c| c == &'\n').take_while(|c| c != &'\n').collect()} }; input_inner!{next, $($r)*}; }; }#[macro_export]macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, static $var:ident : $t:tt $($rest:tt)*) => { $var = read_value!($next, $t); input_inner!{$next $($rest)*} }; ($next:expr, mut $var:ident : $t:tt $($rest:tt)*) => { let mut $var = read_value!($next, $t);input_inner!{$next $($rest)*} }; ($next:expr, $var:ident : $t:tt $($rest:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($rest)*} }; }#[macro_export]macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; all ]) => { { let mut str =$next(false); str.split_whitespace().map(|it| it.parse::<$t>().unwrap()).collect::<Vec<_>>() } }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len as usize).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, lines) => { { let mut vec = Vec::new(); let mut str = $next(false); while str != "" { vec.push(str); str =$next(false); } vec } }; ($next:expr, line) => { $next(false) }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next(true).parse::<$t>().expect("Parse error") }; }// min, max#[macro_export]macro_rules! min { ($a:expr $(,)*) => {{ $a }}; ($a:expr, $b:expr $(,)*) => {{ std::cmp::min($a, $b) }}; ($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::min($a, min!($($rest),+)) }}; }#[macro_export]macro_rules! max { ($a:expr $(,)*) => {{ $a }}; ($a:expr, $b:expr $(,)*) => {{ std::cmp::max($a, $b) }}; ($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::max($a, max!($($rest),+)) }}; }// chmin, chmax#[macro_export]macro_rules! chmin { ($base:expr, $($cmps:expr),+ $(,)*) => {{ let cmp_min = min!($($cmps),+); if $base > cmp_min { $base = cmp_min; true } else {false } }}; }#[macro_export]macro_rules! chmax { ($base:expr, $($cmps:expr),+ $(,)*) => {{ let cmp_max = max!($($cmps),+); if $base < cmp_max { $base = cmp_max; true } else {false } }}; }}