結果

問題 No.1966 Median of Divisors
ユーザー kokatsukokatsu
提出日時 2022-06-03 23:19:25
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 199,948 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-04 17:21:45
合計ジャッジ時間 5,913 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 151 ms
4,384 KB
testcase_05 AC 223 ms
4,384 KB
testcase_06 AC 207 ms
4,380 KB
testcase_07 AC 19 ms
4,380 KB
testcase_08 AC 108 ms
4,380 KB
testcase_09 AC 142 ms
4,380 KB
testcase_10 AC 143 ms
4,380 KB
testcase_11 AC 81 ms
4,384 KB
testcase_12 AC 108 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long T;
    readf("%d\n", T);

    long MOD = 10 ^^ 9 + 7;

    long inv2 = powMod(2, MOD-2, MOD);
    long inv3 = powMod(3, MOD-2, MOD);

    foreach (i; 0 .. T) {
        long N, M;
        readf("%d %d\n", N, M);

        long a = powMod(N, M, MOD), b = powMod(N, M/2, MOD);

        long u = (a * (a + 1) % MOD) * inv2 % MOD;
        long v = (((((b * (b + 1) % MOD) * inv2) % MOD) * (b * 2 + 1)) % MOD) * inv3 % MOD;

        long res = (MOD + u - v) % MOD;
        res.writeln;
    }
}

long powMod(long x, long y, long z) {
    long res = 1;
    while (y > 0) {
        if (y % 2 == 1) {
            res *= x;
            if (res > z) res %= z;
        }
        x *= x;
        if (x > z) x %= z;
        y /= 2;
    }
    return res;
}
0