結果

問題 No.673 カブトムシ
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-05-14 17:42:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 144,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 20:40:59
合計ジャッジ時間 2,118 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

i64 b,c,d;

i64 MOD = 1e9 + 7;

i64 pow(i64 x,i64 y){
    i64 res = 1;

    while(y > 0){
        if(y & 1) res = (res * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return res;
}
i64 inv_mod(i64 a, i64 m = MOD) {
  i64 b, x, u, q, abs_m, tmp;

  abs_m = (m < 0) ? -m : m;
  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? abs_m + x : x;
}
int main(){
    cin >> b >> c >> d;
    b %= MOD;
    c %= MOD;
    /**
     * bc + bc^2 + ... + bc^d =
     * b * (c ^ (d + 1) - 1 / (c - 1) - 1
     */

    i64 sum = (pow(c,d + 1) + MOD - 1) % MOD * inv_mod((c + MOD - 1) % MOD);

    cout << (b * ((sum + MOD - 1) % MOD)) % MOD << endl;
}
0