結果

問題 No.391 CODING WAR
ユーザー At-sushiAt-sushi
提出日時 2020-06-02 18:00:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 148,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-15 21:02:33
合計ジャッジ時間 1,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 38 ms
4,380 KB
testcase_10 AC 37 ms
4,376 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 28 ms
4,376 KB
testcase_15 AC 32 ms
4,380 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 23 ms
4,376 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 AC 16 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: function `nfactorial` is never used
 --> Main.rs:7:4
  |
7 | fn nfactorial(x: i64, y: i64) -> i64 {
  |    ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn getline() -> String{
	let mut __ret=String::new();
	std::io::stdin().read_line(&mut __ret).ok();
	return __ret;
}

fn nfactorial(x: i64, y: i64) -> i64 {
    match y {
        0 => 1,
        _ => x * nfactorial(x-1, y-1) % 1000000007
    }
}

fn mpow( x: i64,  y: i64) -> i64 {
    let (mut r,mut xx,mut yy) = (1, x, y);
    
    while yy > 0 {
        if (yy % 2) == 1 {
            r = (r * xx) % 1000000007;
        }
        yy /= 2;
        xx = (xx * xx) % 1000000007;
    }
    
    return r;
}

fn main(){
	let s=getline();
	let a:Vec<_>=s.trim().split(' ').collect();
	let (n, m): (i64, i64) = (a[0].parse().unwrap(), a[1].parse().unwrap());
	let mut r = mpow(m, n);
	let mut zeros = m;
	let mut zdiv =1;
	(1..m).for_each(|i| {
	    let patterns = mpow(m-i, n) % 1000000007;
	    
	    r = (if (i % 2) == 0 {r + patterns * (zeros * mpow(zdiv, 1000000007-2) % 1000000007) % 1000000007} else {(r + 1000000007 - patterns * (zeros * mpow(zdiv, 1000000007-2) % 1000000007) % 1000000007) % 1000000007}) % 1000000007;
	    zeros = zeros * (m-i) % 1000000007;
	    zdiv = zdiv * (i+1) % 1000000007;
	});
	print!("{} ", r);
}
0