結果

問題 No.886 Direct
ユーザー beetbeet
提出日時 2019-09-13 22:30:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,889 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 199,496 KB
実行使用メモリ 27,088 KB
最終ジャッジ日時 2023-09-17 14:48:34
合計ジャッジ時間 6,242 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
26,884 KB
testcase_01 AC 42 ms
26,852 KB
testcase_02 AC 43 ms
26,916 KB
testcase_03 AC 42 ms
26,776 KB
testcase_04 AC 43 ms
26,712 KB
testcase_05 AC 42 ms
26,824 KB
testcase_06 AC 44 ms
26,880 KB
testcase_07 AC 43 ms
26,700 KB
testcase_08 AC 44 ms
26,948 KB
testcase_09 AC 44 ms
26,712 KB
testcase_10 AC 44 ms
26,912 KB
testcase_11 AC 53 ms
26,816 KB
testcase_12 AC 53 ms
26,756 KB
testcase_13 AC 46 ms
26,700 KB
testcase_14 AC 63 ms
26,708 KB
testcase_15 AC 43 ms
26,712 KB
testcase_16 AC 45 ms
26,896 KB
testcase_17 AC 46 ms
26,760 KB
testcase_18 AC 44 ms
26,756 KB
testcase_19 AC 45 ms
26,900 KB
testcase_20 AC 44 ms
26,764 KB
testcase_21 AC 44 ms
26,912 KB
testcase_22 AC 43 ms
26,700 KB
testcase_23 AC 67 ms
26,712 KB
testcase_24 AC 127 ms
27,028 KB
testcase_25 AC 99 ms
26,716 KB
testcase_26 AC 59 ms
26,948 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 45 ms
26,848 KB
testcase_30 AC 206 ms
26,844 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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};
  Int len=h/d;
  res+=M(len*(len-1)/2)*M(d);

  Int num=h%d;
  res+=M(h/d)*M(num);
  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