結果
| 問題 | No.673 カブトムシ | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2018-04-13 22:53:12 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 933 bytes | 
| コンパイル時間 | 602 ms | 
| コンパイル使用メモリ | 74,460 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-30 05:53:42 | 
| 合計ジャッジ時間 | 1,276 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
constexpr int P = 1000000007;
int inv(int n) {
    int m = P, y = 0, v = 1;
    while (1) {
        int q = m / n;
        int r = m % n;
        if (r == 0) return v < 0 ? v + P : v;
        y -= v * q;
        swap(y, v);
        m = n;
        n = r;
    }
}
ll pow(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r % P;
}
int main() {
    ll b, c, d;
    cin >> b >> c >> d;
    b %= P;
    c %= P;
    if (c == 1) {
        cout << b * (d % P) % P << endl;
        return 0;
    }
    ll cc = pow(c, d);
    cc--; if (cc < 0) cc += P;
    ll c1 = c;
    c1--; if (c1 < 0) c1 += P;
    cout << b * c % P * cc % P * inv(c1) % P << endl;
    return 0;
}
            
            
            
        