結果

問題 No.673 カブトムシ
ユーザー ikdikd
提出日時 2018-04-13 23:23:29
言語 D
(dmd 2.107.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 838 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 154,160 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 19:27:28
合計ジャッジ時間 2,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  BigInt b, c, d; rd(b, c, d);

  const BigInt mod=1_000_000_000+7;

  BigInt pow(BigInt a, BigInt x){
    if(x==0) return cast(BigInt)1;
    else if(x==1) return a;
    else if(x&1) return a*pow(a, x-1)%mod;
    else return pow(a*a%mod, x/2);
  }

  BigInt inv(BigInt x){
    return pow(x, mod-2);
  }

  BigInt ret=b;
  if(c==1){
    ret=ret*d;
  }else{
    ret=ret*c;
    ret=ret*(pow(c, d)-1);
    ret=ret*inv(c-1);
  }

  writeln(ret%mod);
}

/+
  1. B*C
  2. (B*C+B)*C
  3. ((B*C+B)*C+B)*C
  4. (((B*C+B)*C+B)*C+B)*C=B(C^4+C^3+C^2+C)

  C+C^2+...+C^D = C*(C^D-1)/(C-1)
+/

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