結果

問題 No.1966 Median of Divisors
ユーザー Nzt3Nzt3
提出日時 2022-06-03 22:49:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 536 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 167,804 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 02:13:15
合計ジャッジ時間 3,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 60 ms
4,348 KB
testcase_05 AC 68 ms
4,348 KB
testcase_06 AC 65 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 43 ms
4,348 KB
testcase_09 AC 57 ms
4,348 KB
testcase_10 AC 57 ms
4,348 KB
testcase_11 AC 26 ms
4,348 KB
testcase_12 AC 34 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long modpow(int a,int n){
  long long ret=1,t=a;
  for(int i=0;i<30;i++){
    if(n>>i&1)ret=ret*t%mod;
    t=t*t%mod;
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin>>T;
  const int inv6=modpow(6,mod-2),inv2=modpow(2,mod-2);
  while(T--){
    long long N,M;
    cin>>N>>M;
    long long k=modpow(N,M),k2=modpow(N,M/2);
    cout<<((k*(k+1)%mod*inv2%mod-k2*(k2+1)%mod*(k2*2+1)%mod*inv6%mod)%mod+mod)%mod<<'\n';
  }
}
0