結果

問題 No.1966 Median of Divisors
ユーザー monnumonnu
提出日時 2022-06-03 21:58:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 3,877 ms
コンパイル使用メモリ 229,004 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 01:51:02
合計ジャッジ時間 6,427 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 3 ms
4,348 KB
testcase_04 AC 200 ms
4,348 KB
testcase_05 AC 245 ms
4,348 KB
testcase_06 AC 243 ms
4,348 KB
testcase_07 AC 25 ms
4,348 KB
testcase_08 AC 147 ms
4,348 KB
testcase_09 AC 196 ms
4,348 KB
testcase_10 AC 202 ms
4,348 KB
testcase_11 AC 87 ms
4,348 KB
testcase_12 AC 115 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000000000000
#define MOD 1000000007
#define MAX 1000000

ll modpow(ll a,ll n,ll mod=MOD){
  ll res=1;
  a%=mod;
  while(n>0){
    if(n&1){
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a,ll mod=MOD){
  return modpow(a,mod-2,mod);
}

void solve(){
  ll N,M;
  cin>>N>>M;

  ll x=modpow(N,M);
  ll ans=x*(x+1)/2;
  ans%=MOD;
  ll y=modpow(N,M/2);
  ans+=MOD-((y*(y+1)%MOD)*(2*y+1)%MOD)*modinv(6)%MOD;
  ans%=MOD;
  cout<<ans<<'\n';
}

int main(){
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
    solve();
  }
}
0