結果

問題 No.673 カブトムシ
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-05-14 17:47:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 1,260 ms
コンパイル使用メモリ 144,596 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 19:03:42
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 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;
    if(c == 1) sum = d + 1;
    else sum = (((pow(c,d + 1) + MOD - 1) % MOD) * (inv_mod((c + MOD - 1) % MOD) % MOD)) % MOD;

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