結果

問題 No.1966 Median of Divisors
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-09 07:44:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 1,262 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 68,260 KB
実行使用メモリ 32,112 KB
最終ジャッジ日時 2023-10-09 07:44:24
合計ジャッジ時間 7,130 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,876 KB
testcase_01 AC 61 ms
21,860 KB
testcase_02 AC 60 ms
23,860 KB
testcase_03 AC 67 ms
21,864 KB
testcase_04 AC 307 ms
30,344 KB
testcase_05 AC 411 ms
30,316 KB
testcase_06 AC 447 ms
30,480 KB
testcase_07 AC 86 ms
23,872 KB
testcase_08 AC 236 ms
31,020 KB
testcase_09 AC 293 ms
32,064 KB
testcase_10 AC 286 ms
32,112 KB
testcase_11 AC 203 ms
29,404 KB
testcase_12 AC 228 ms
25,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new long[t];
        var mod = 1_000_000_007;
        var r2 = Exp(2, mod - 2, mod);
        var r6 = Exp(6, mod - 2, mod);
        for (var u = 0; u < t; ++u)
        {
            var c = NList;
            var (n, m) = (c[0], c[1]);
            var nm = Exp(n, m, mod);
            var nm2 = Exp(n, m / 2, mod);
            ans[u] = (nm * (nm + 1) % mod * r2 % mod + mod - nm2 * (nm2 + 1) % mod * (2 * nm2 + 1) % mod * r6 % mod) % mod;
        }
        WriteLine(string.Join("\n", ans));
    }
    static long Exp(long n, long k, int mod)
    {
        if (k == 0) return 1;
        if (k == 1) return n % mod;
        var half = Exp(n, k / 2, mod);
        var result = (half * half) % mod;
        return ((k % 2) == 0) ? result : ((result * n) % mod);
    }
}
0