結果

問題 No.673 カブトムシ
ユーザー ikdikd
提出日時 2018-04-13 23:33:42
言語 D
(dmd 2.106.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 892 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 88,532 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 19:27:31
合計ジャッジ時間 1,666 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

  const long mod=1_000_000_000+7;

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

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

  long ret=b%mod;
  if(c==1){
    ret=ret*(d%mod)%mod;
  }else{
    ret=ret*(c%mod)%mod;
    ret=ret*((pow(c, d)-1+mod)%mod)%mod;
    ret=ret*inv(c-1)%mod;
  }

  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