結果

問題 No.673 カブトムシ
ユーザー 0w10w1
提出日時 2020-11-16 16:21:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 1,971 ms
コンパイル使用メモリ 199,992 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 07:18:56
合計ジャッジ時間 3,017 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<int m>
struct Mint {
  int v;
  Mint(int _v = 0) : v(_v) { v %= m; adjust(); }
  void adjust() { if (v < 0) v += m; if (v >= m) v -= m; assert(0 <= v && v < m); }
  Mint operator+() const { return *this; }
  Mint operator-() const { Mint r = Mint(0) - *this; return r.adjust(), r; }
  friend Mint operator+(Mint a, Mint b) { a.v += b.v; return a.adjust(), a; }
  Mint& operator+=(const Mint &b) { return v += b.v, adjust(), *this; }
  friend Mint operator-(Mint a, Mint b) { a.v -= b.v; return a.adjust(), a; }
  Mint& operator-=(const Mint &b) { return v -= b.v, adjust(), *this; }
  friend Mint operator*(Mint a, Mint b) { a.v = (int64_t) a.v * b.v % m; return a.adjust(), a; }
  friend Mint operator*(Mint a, int v) { return a * Mint(v); }
  friend Mint operator^(Mint a, int p) {
    int v = a.v;
    int r = 1;
    for (int i = p; i; i >>= 1) {
      if (i & 1) r = (int64_t) r * v % m;
      v = (int64_t) v * v % m;
    }
    return r;
  }
  friend Mint operator^(Mint a, Mint p) { return a^p.v; }
  friend Mint operator/(Mint a, Mint b) { return a * (Mint(b.v)^(m-2)); }
  friend ostream& operator<<(ostream &os, Mint a) { return os << a.v, os; }
};

int main() {
  ios::sync_with_stdio(false);

  const int M = 1e9 + 7;

  int64_t B, C, D; { cin >> B >> C >> D; }
  B %= M;
  C %= M;

  Mint<M> res = C > 1 ? (((Mint<M>(C)^(D%(M-1)+1)) - 1) / (Mint<M>(C) - 1) - 1) * B : Mint<M>(B) * (D % M);
  cout << res << endl;
}

0