結果

問題 No.573 a^2[i] = a[i]
ユーザー uenokuuenoku
提出日時 2017-10-10 00:13:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 4,425 ms
コンパイル使用メモリ 146,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 21:24:40
合計ジャッジ時間 5,239 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 21 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around function argument
  --> Main.rs:14:38
   |
14 |         inv[i + 1] = (inv[i] * (powm((i + 1), _mod - 2))) % _mod;
   |                                      ^     ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
14 -         inv[i + 1] = (inv[i] * (powm((i + 1), _mod - 2))) % _mod;
14 +         inv[i + 1] = (inv[i] * (powm(i + 1, _mod - 2))) % _mod;
   |

warning: function `add` is never used
  --> Main.rs:29:4
   |
29 | fn add(a: &mut usize, b: usize) {
   |    ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: constant `_mod` should have an upper case name
 --> Main.rs:4:7
  |
4 | const _mod: usize = 1000000007;
  |       ^^^^ help: convert the identifier to upper case: `_MOD`
  |
  = note: `#[warn(non_upper_case_globals)]` on by default

warning: 3 warnings emitted

ソースコード

diff #

use std::io::{stdin, Read};
use std::str::FromStr;

const _mod: usize = 1000000007;

fn main() {
    let n: usize = read();
    let mut inv = vec![0; 2 * n + 10];
    let mut f = vec![0; 2 * n + 10];
    f[0] = 1;
    inv[0] = 1;
    for i in 0..n + 10 {
        f[i + 1] = (f[i] * (i + 1)) % _mod;
        inv[i + 1] = (inv[i] * (powm((i + 1), _mod - 2))) % _mod;
    }

    let mut ans = 0;
    for i in 1..n + 1 {
        let mut tmp = powm(i, n - i);
        tmp *= (inv[i] * inv[n - i]) % _mod * f[n] % _mod;
        ans += tmp;
        ans %= _mod;
    }
    println!("{}", ans);
}



fn add(a: &mut usize, b: usize) {
    *a = (*a + b + _mod) % _mod;
}
fn powm(a: usize, p: usize) -> usize {
    let mut ans = 1;
    let mut a = a.clone();
    let mut p = p.clone();
    while p > 0 {
        if p % 2 == 1 {
            ans *= a;
        }
        a = (a * a) % _mod;
        ans %= _mod;
        p /= 2;
    }
    ans
}
#[allow(dead_code)]
fn read_str() -> Vec<char> {
    let s: String = read();
    s.chars().collect::<Vec<char>>()
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(
        |_| panic!("Faild to parse {}", s),
    )
}
0