結果

問題 No.1966 Median of Divisors
コンテスト
ユーザー polyester
提出日時 2022-06-03 22:33:06
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 883 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,981 ms
コンパイル使用メモリ 155,344 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-09 10:47:20
合計ジャッジ時間 3,972 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
ll modpow(ll x, ll n) {
  ll ans = 1;
  while(n > 0) {
    if(n % 2 == 1) {
      ans *= x;
      ans %= MOD;
    }
    x *= x;
    x %= MOD;
    n >>= 1;
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  while(t--) {
    ll n, m;
    cin >> n >> m;
    ll maxi = modpow(n, m);
    ll sum = maxi * (maxi + 1) % MOD * 500000004 % MOD;
    ll div = modpow(n, m / 2);
    cout << (sum -
             div % MOD * (div % MOD + 1) % MOD * (2 * div % MOD + 1) % MOD *
                 166666668 % MOD +
             MOD) %
                MOD
         << endl;
  }
  return 0;
}
0