結果

問題 No.886 Direct
ユーザー beetbeet
提出日時 2021-11-21 11:49:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 4,000 ms
コード長 3,232 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 203,604 KB
実行使用メモリ 27,160 KB
最終ジャッジ日時 2023-09-04 20:30:03
合計ジャッジ時間 9,685 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
26,760 KB
testcase_01 AC 162 ms
26,888 KB
testcase_02 AC 160 ms
26,896 KB
testcase_03 AC 162 ms
27,008 KB
testcase_04 AC 187 ms
26,888 KB
testcase_05 AC 180 ms
26,952 KB
testcase_06 AC 185 ms
26,772 KB
testcase_07 AC 157 ms
26,812 KB
testcase_08 AC 155 ms
27,000 KB
testcase_09 AC 168 ms
26,764 KB
testcase_10 AC 162 ms
26,812 KB
testcase_11 AC 153 ms
26,816 KB
testcase_12 AC 156 ms
26,896 KB
testcase_13 AC 156 ms
26,952 KB
testcase_14 AC 155 ms
27,160 KB
testcase_15 AC 168 ms
26,956 KB
testcase_16 AC 168 ms
26,868 KB
testcase_17 AC 169 ms
26,828 KB
testcase_18 AC 183 ms
26,868 KB
testcase_19 AC 166 ms
27,032 KB
testcase_20 AC 165 ms
26,836 KB
testcase_21 AC 174 ms
26,960 KB
testcase_22 AC 165 ms
26,840 KB
testcase_23 AC 158 ms
26,864 KB
testcase_24 AC 169 ms
26,864 KB
testcase_25 AC 168 ms
26,828 KB
testcase_26 AC 182 ms
26,812 KB
testcase_27 AC 163 ms
26,996 KB
testcase_28 AC 162 ms
26,948 KB
testcase_29 AC 154 ms
26,996 KB
testcase_30 AC 161 ms
26,768 KB
testcase_31 AC 182 ms
27,032 KB
testcase_32 AC 174 ms
26,768 KB
testcase_33 AC 160 ms
26,840 KB
testcase_34 AC 166 ms
26,988 KB
testcase_35 AC 178 ms
26,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif
// https://noshi91.hatenablog.com/entry/2019/09/23/002445
//BEGIN CUT HERE
// O(n \log \log n)
namespace DivisorTransform{
  template<typename T, typename F>
  void inc(vector<T> &as,F f){
    assert(as[0]==T(0));
    int n=as.size();
    vector<bool> sieve(n,false);
    for(int p=2;p<n;p++){
      if(sieve[p]) continue;
      for(int k=1;k*p<n;k++){
        sieve[k*p]=true;
        f(as[k],as[k*p]);
      }
    }
  }
  template<typename T, typename F>
  void dec(vector<T> &as,F f){
    assert(as[0]==T(0));
    int n=as.size();
    vector<bool> sieve(n,false);
    for(int p=2;p<n;p++){
      if(sieve[p]) continue;
      for(int k=(n-1)/p;k!=0;--k){
        sieve[k*p]=true;
        f(as[k],as[k*p]);
      }
    }
  }
}
namespace GCDConvolution{
  template<typename T>
  void zeta(vector<T> &as){
    auto f=[](T &lo,T &hi){lo+=hi;};
    DivisorTransform::dec(as,f);
  }
  template<typename T>
  void moebius(vector<T> &as){
    auto f=[](T &lo,T &hi){lo-=hi;};
    DivisorTransform::inc(as,f);
  }
}
namespace LCMConvolution{
  template<typename T>
  void zeta(vector<T> &as){
    auto f=[](T &lo,T &hi){hi+=lo;};
    DivisorTransform::inc(as,f);
  }
  template<typename T>
  void moebius(vector<T> &as){
    auto f=[](T &lo,T &hi){hi-=lo;};
    DivisorTransform::dec(as,f);
  }
}
//END CUT HERE
#ifndef call_from_test

template<typename T, T MOD = 1000000007>
struct Mint{
  inline 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 *this;}
  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;}

  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>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
signed main(){
  const int MAX = 3e6+100;
  using M = Mint<int>;
  vector<M> ys(MAX,0),xs(MAX,0);

  int h,w;
  cin>>h>>w;
  for(int i=1;i<h;i++) ys[i]=h-i;
  for(int j=1;j<w;j++) xs[j]=w-j;

  GCDConvolution::zeta(ys);
  GCDConvolution::zeta(xs);
  for(int i=1;i<MAX;i++) ys[i]*=xs[i];
  GCDConvolution::moebius(ys);

  M ans{0};
  ans+=ys[1]*M(2);
  ans+=M(h-1)*M(w);
  ans+=M(h)*M(w-1);
  cout<<ans<<endl;

  return 0;
}
#endif
0