結果

問題 No.1966 Median of Divisors
ユーザー AngrySadEightAngrySadEight
提出日時 2022-06-03 22:34:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 170,180 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 02:07:43
合計ジャッジ時間 5,934 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 353 ms
4,348 KB
testcase_05 AC 432 ms
4,348 KB
testcase_06 AC 415 ms
4,348 KB
testcase_07 AC 42 ms
4,348 KB
testcase_08 AC 247 ms
4,348 KB
testcase_09 AC 330 ms
4,348 KB
testcase_10 AC 332 ms
4,348 KB
testcase_11 AC 156 ms
4,348 KB
testcase_12 AC 208 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
typedef long long ll;

ll my_pow(ll x, ll n, ll mod){
    // 繰り返し二乗法.x^nをmodで割った余り.
    ll ret;
    if (n == 0){
        ret = 1;
    }
    else if (n % 2 == 1){
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    }
    else{
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

int main(){
    ll T;
    cin >> T;
    for (ll z = 0; z < T; z++){
        ll N, M;
        cin >> N >> M;
        ll x = my_pow(N, M, mod1);
        ll y = my_pow(N, M / 2, mod1);
        ll s1 = (x * (x + 1)) % mod1;
        s1 = (s1 * my_pow(2LL, mod1 - 2, mod1)) % mod1;

        ll s2 = (y * (y + 1)) % mod1;
        s2 = (s2 * (2 * y + 1)) % mod1;
        s2 = (s2 * my_pow(6LL, mod1 - 2, mod1)) % mod1;
        cout << (s1 - s2 + mod1) % mod1 << endl;
    }
}
0