結果
問題 | No.1966 Median of Divisors |
ユーザー |
![]() |
提出日時 | 2022-06-03 21:58:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 276 ms / 2,000 ms |
コード長 | 718 bytes |
コンパイル時間 | 4,065 ms |
コンパイル使用メモリ | 230,144 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 02:42:00 |
合計ジャッジ時間 | 6,859 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#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(); } }