結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー umezoumezo
提出日時 2021-10-30 00:09:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,072 bytes
コンパイル時間 2,702 ms
コンパイル使用メモリ 213,400 KB
実行使用メモリ 768,284 KB
最終ジャッジ日時 2024-04-16 16:02:55
合計ジャッジ時間 7,469 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 152 ms
31,872 KB
testcase_06 AC 516 ms
40,064 KB
testcase_07 AC 253 ms
27,008 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;

ll modpow(ll x,ll n){
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}

vector<ll> divisor(ll x){
  set<ll> s;
  for(ll i=1;i*i<=x;i++){
    if(x%i==0){
      s.insert(i);
      s.insert(x/i);
    }
  }
  vector<ll> res;
  for(auto y:s) res.push_back(y);
  sort(ALL(res));
  reverse(ALL(res));
  return res;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int t;
  cin>>t;
  while(t--){
    ll n,c;
    cin>>n>>c;
    
    ll ans=modpow(c,n)*n%MOD;
    
    vector<ll> A=divisor(n);
    map<ll,ll> m;
    ll cnt=0;
    for(auto t:A){
      if(t==1){
        ans=(ans+(n-cnt)*modpow(c,2)%MOD)%MOD;
        break;
      }
      ll tmp=n/t;
      for(int i=2*t;i<=n;i+=t) tmp-=m[i];
      ans=(ans+tmp*modpow(c,2*t)%MOD)%MOD;
      m[t]=tmp;
      cnt+=tmp;
    }
    cout<<ans*modpow(2*n,MOD-2)%MOD<<endl;
  }
    
  return 0;
}
0