結果
問題 | No.573 a^2[i] = a[i] |
ユーザー |
|
提出日時 | 2017-10-06 23:22:05 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 2,932 bytes |
コンパイル時間 | 12,743 ms |
コンパイル使用メモリ | 377,416 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 01:58:17 |
合計ジャッジ時間 | 13,532 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
コンパイルメッセージ
warning: fields `n` and `inv` are never read --> src/main.rs:8:5 | 6 | struct Combination { | ----------- fields in this struct 7 | modular: usize, 8 | n: usize, | ^ 9 | fact: Vec<usize>, 10 | inv: Vec<usize>, | ^^^ | = note: `Combination` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default
ソースコード
#[allow(dead_code)]const MOD: usize = 1_000000000 + 7;#[derive(Debug)]struct Combination {modular: usize,n: usize,fact: Vec<usize>,inv: Vec<usize>,invfact: Vec<usize>,}impl Combination {fn new(modular: usize, n: usize) -> Self {let mut fact = vec![0; n+1];let mut inv = vec![0; n+1];let mut invfact = vec![0; n+1];inv[1] = 1;fact[0] = 1;invfact[0] = 1;for i in 2..inv.len() {inv[i] = inv[modular % i] * (modular - modular / i) % modular;}for i in 1..inv.len() {fact[i] = i * fact[i-1] % modular;invfact[i] = inv[i] * invfact[i-1] % modular;}Combination {modular,n,fact,inv,invfact,}}fn comb(&self, n: usize, r: usize) -> usize {self.fact[n] * self.invfact[n-r] % self.modular * self.invfact[r] % self.modular}}fn modpow(n: usize, r: usize) -> usize {if r == 0 { return 1; }if r == 1 { return n; }let x = modpow(n, r / 2);if r % 2 == 0 {x * x % MOD} else {x * x % MOD * n % MOD}}fn main() {let mut cin = Scanner::new();// Σ C(n,i)*i^(n-i)let n = cin.next_usize();let c = Combination::new(MOD, n+1);let mut ans = 0;for i in 1..(n+1) {// println!("{} {} {}", i, c.comb(n, i), modpow(i, n-i));ans += c.comb(n, i) * modpow(i, n-i) % MOD;}println!("{}", ans % MOD);}struct Scanner {reader: std::io::Stdin,tokens: std::collections::VecDeque<String>,}impl Scanner {fn new() -> Self {Scanner {reader: std::io::stdin(),tokens: std::collections::VecDeque::new(),}}fn next(&mut self) -> String {if self.tokens.is_empty() {let mut s = String::new();loop {self.reader.read_line(&mut s).ok();let s = s.trim();if s.len() != 0 {for it in s.split_whitespace() {self.tokens.push_back(it.into())}break;}}}self.tokens.pop_front().unwrap()}fn next_generics<T>(&mut self) -> T whereT: std::str::FromStr + std::marker::Copy,<T as std::str::FromStr>::Err: std::fmt::Debug{self.next().parse().unwrap()}#[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::<i32>() }#[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::<i64>() }#[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::<u64>() }#[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::<usize>() }#[allow(dead_code)] fn next_isize(&mut self) -> isize { self.next_generics::<isize>() }}