結果

問題 No.573 a^2[i] = a[i]
ユーザー ikdikd
提出日時 2017-10-07 11:32:30
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 84,244 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 16:19:23
合計ジャッジ時間 2,359 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 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 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 3 ms
4,376 KB
testcase_42 AC 4 ms
4,380 KB
testcase_43 AC 5 ms
4,376 KB
testcase_44 AC 7 ms
4,376 KB
testcase_45 AC 13 ms
4,380 KB
testcase_46 AC 127 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class C{
  // public:
  long[] fac, inv;
  long mod=1_000_000_000+7;
  this(int n){
    fac.length=n+1;
    fac[0]=fac[1]=1;
    for(int i=2; i<=n; i++) fac[i]=i*fac[i-1]%mod;
    inv.length=n+1;
    for(int i=0; i<=n; i++) inv[i]=pow(fac[i], mod-2);
  }
  long pow(long a, long x){
    if(x==0) return 1;
    else if(x==1) return a;
    else if(x%2==0) return pow(a*a%mod, x/2);
    else return a*pow(a, x-1)%mod;
  }
  long comb(int n, int k){
    if(n<k) return 0;
    else return (fac[n]*inv[n-k]%mod)*inv[k]%mod;
  }
}


void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto c=new C(n);
  long cnt=0, mod=c.mod;
  for(int i=1; i<=n; i++){
    (cnt+=c.comb(n, i)*c.pow(i, n-i)%mod)%=mod;
  }
  
  writeln(cnt);
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0