結果

問題 No.1966 Median of Divisors
ユーザー HaaHaa
提出日時 2022-06-03 21:50:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 168,188 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 01:47:50
合計ジャッジ時間 3,991 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 228 ms
4,348 KB
testcase_05 AC 263 ms
4,348 KB
testcase_06 AC 263 ms
4,348 KB
testcase_07 AC 27 ms
4,348 KB
testcase_08 AC 160 ms
4,348 KB
testcase_09 AC 222 ms
4,348 KB
testcase_10 AC 219 ms
4,348 KB
testcase_11 AC 93 ms
4,348 KB
testcase_12 AC 129 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

ll divid(ll x, ll y){
    x%=MOD;
    return x*power(y,MOD-2)%MOD;
}

ll spn(ll n){
    n%=MOD;
    return divid(n*(n+1)%MOD*(n*2+1)%MOD,6);
}

void solve(){
    ll n, m; cin >> n >> m;
    ll nm=power(n,m);
    cout << (divid(nm*(nm+1),2)-spn(power(n,m/2))+MOD)%MOD << endl;
}

int main(){
    int t; cin >> t;
    while(t--) solve();
    return 0;
}
0