結果
| 問題 | No.673 カブトムシ | 
| コンテスト | |
| ユーザー |  ikd | 
| 提出日時 | 2018-04-13 23:23:29 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 838 bytes | 
| コンパイル時間 | 1,819 ms | 
| コンパイル使用メモリ | 155,796 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-13 00:25:40 | 
| 合計ジャッジ時間 | 2,415 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 12 WA * 2 | 
ソースコード
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));
}
            
            
            
        