結果

問題 No.886 Direct
ユーザー beetbeet
提出日時 2019-09-13 22:27:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,842 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 200,624 KB
実行使用メモリ 31,212 KB
最終ジャッジ日時 2023-09-17 14:47:06
合計ジャッジ時間 22,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
27,056 KB
testcase_01 AC 46 ms
27,016 KB
testcase_02 AC 48 ms
26,816 KB
testcase_03 AC 664 ms
26,936 KB
testcase_04 AC 49 ms
26,768 KB
testcase_05 AC 44 ms
26,824 KB
testcase_06 AC 44 ms
26,824 KB
testcase_07 AC 41 ms
26,760 KB
testcase_08 AC 41 ms
26,712 KB
testcase_09 AC 42 ms
26,884 KB
testcase_10 AC 45 ms
26,936 KB
testcase_11 AC 48 ms
26,712 KB
testcase_12 AC 41 ms
26,820 KB
testcase_13 AC 46 ms
26,728 KB
testcase_14 AC 44 ms
26,724 KB
testcase_15 AC 45 ms
26,880 KB
testcase_16 AC 43 ms
26,708 KB
testcase_17 AC 558 ms
26,728 KB
testcase_18 TLE -
testcase_19 AC 2,188 ms
26,888 KB
testcase_20 AC 511 ms
26,728 KB
testcase_21 AC 776 ms
26,880 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  // find x s.t. a^x = b
  static T log(T a,T b){
    const T sq=40000;
    unordered_map<T, T> dp;
    dp.reserve(sq);
    Mint res(1);
    for(Int r=0;r<sq;r++){
      if(!dp.count(res.v)) dp[res.v]=r;
      res*=a;
    }
    Mint p=Mint(a).inv().pow(sq);
    res=b;
    for(Int q=0;q<=MOD/sq+1;q++){
      if(dp.count(res.v)){
        T idx=q*sq+dp[res.v];
        if(idx>0) return idx;
      }
      res*=p;
    }
    assert(0);
    return T(-1);
  }

  static Mint comb(long long n,Int k){
    Mint num(1),dom(1);
    for(Int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
const Int MAX = 1e6+10;
Int dp[MAX]={};
Int pr[MAX]={};
Int mu[MAX]={};
using M = Mint<Int>;

Int h,w;
// sum floor(i / d), i = 1 to h-1
M calc(Int d){
  M res{0};
  for(Int i=1;i<h;i++) res+=M(i/d);
  return res;
}

signed main(){
  for(Int i=1;i<MAX;i++) mu[i]=1;
  for(Int i=2;i<MAX;i++){
    if(dp[i]) continue;
    pr[i]=1;
    mu[i]=-1;
    for(Int j=i+i;j<MAX;j+=i) dp[j]=1,mu[j]*=-1;
    for(Int j=i*i;j<MAX;j+=i*i) mu[j]=0;
  }
  cin>>h>>w;

  M ans{0};
  for(Int d=1;d<w;d++){
    M t{0};
    for(Int i=d;i<w;i+=d) t+=M(w-i);
    ans+=t*M(mu[d])*calc(d);
  }

  // double ans
  ans*=2;

  // horizontal & vertical
  ans+=M(h)*M(w-1);
  ans+=M(h-1)*M(w);

  cout<<ans<<endl;
  return 0;
}
0