結果
問題 |
No.1126 SUM
|
ユーザー |
|
提出日時 | 2020-09-27 13:43:24 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 39 ms / 1,000 ms |
コード長 | 1,117 bytes |
コンパイル時間 | 13,228 ms |
コンパイル使用メモリ | 402,332 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 12:00:12 |
合計ジャッジ時間 | 15,232 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
const DIVISIOR: u64 = 1_000_000_007; fn power(base: u64, p: u64) -> u64 { if p == 0 { return 1u64; } if p == 1 { return base; } let temp: u64 = power(base, p / 2u64); temp * temp % DIVISIOR * power(base, p % 2) % DIVISIOR } fn comb(n: u64, r: u64, nums: &Vec<u64>, dens: &Vec<u64>) -> u64 { nums[n as usize] * dens[n as usize - r as usize] % DIVISIOR * dens[r as usize] % DIVISIOR } fn main() { let mut nm = String::new(); std::io::stdin().read_line(&mut nm).ok(); let nm: Vec<u64> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nm[0]; let m = nm[1]; let mut nums: Vec<u64> = vec![1; m as usize + 1usize]; let mut dens: Vec<u64> = vec![1; m as usize + 1usize]; for i in 1..=m { nums[i as usize] = nums[i as usize - 1usize] * i; nums[i as usize] %= DIVISIOR; dens[i as usize] = dens[i as usize - 1usize] * power(i, DIVISIOR-2); dens[i as usize] %= DIVISIOR; } let result: u64 = (n..=m) .map(|i| comb(i, n, &nums, &dens)) .sum() ; println!("{}", result % DIVISIOR); }