結果

問題 No.673 カブトムシ
ユーザー nebukuro09
提出日時 2018-04-13 22:41:00
言語 D
(dmd 2.109.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 815 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 115,644 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-13 00:24:40
合計ジャッジ時間 1,586 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!long);
    auto B = s[0];
    auto C = s[1];
    auto D = s[2];
    immutable long MOD = 10^^9 + 7;
    if (C == 1) {
        writeln(B % MOD * (D % MOD) % MOD);
        return;
    }
    long ans = powmod(C%MOD, D+1, MOD) - 1;
    ans = (ans + MOD) % MOD;
    ans = ans * powmod((C-1)%MOD, MOD-2, MOD) % MOD;
    ans = (ans % MOD - 1 + MOD) % MOD;
    ans = B % MOD * ans % MOD;
    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}
0