結果

問題 No.886 Direct
ユーザー beetbeet
提出日時 2021-11-21 11:42:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,179 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 204,352 KB
実行使用メモリ 27,156 KB
最終ジャッジ日時 2023-09-04 20:26:18
合計ジャッジ時間 10,585 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
27,092 KB
testcase_01 AC 174 ms
26,812 KB
testcase_02 AC 169 ms
26,932 KB
testcase_03 WA -
testcase_04 AC 162 ms
26,876 KB
testcase_05 AC 166 ms
27,004 KB
testcase_06 AC 163 ms
27,004 KB
testcase_07 AC 178 ms
26,916 KB
testcase_08 AC 174 ms
26,892 KB
testcase_09 AC 174 ms
26,872 KB
testcase_10 AC 191 ms
26,980 KB
testcase_11 AC 197 ms
26,812 KB
testcase_12 AC 166 ms
26,760 KB
testcase_13 AC 178 ms
26,836 KB
testcase_14 AC 233 ms
26,772 KB
testcase_15 AC 172 ms
26,872 KB
testcase_16 AC 161 ms
26,764 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 157 ms
26,872 KB
testcase_30 AC 155 ms
27,056 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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){
    int n=as.size();
    vector<bool> sieve(n,true);
    for(int p=2;p<n;p++){
      if(!sieve[p]) continue;
      for(int k=1;k*p<n;k++){
        sieve[k*p]=false;
        f(as[k],as[k*p]);
      }
    }
  }
  template<typename T, typename F>
  void dec(vector<T> &as,F f){
    int n=as.size();
    vector<bool> sieve(n,true);
    for(int p=2;p<n;p++){
      if(!sieve[p]) continue;
      for(int k=1;k*p<n;k++){
        sieve[k*p]=false;
        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::inc(as,f);
  }
  template<typename T>
  void moebius(vector<T> &as){
    auto f=[](T &lo,T &hi){lo-=hi;};
    DivisorTransform::dec(as,f);
  }
}
namespace LCMConvolution{
  template<typename T>
  void zeta(vector<T> &as){
    auto f=[](T &lo,T &hi){hi+=lo;};
    DivisorTransform::dec(as,f);
  }
  template<typename T>
  void moebius(vector<T> &as){
    auto f=[](T &lo,T &hi){hi-=lo;};
    DivisorTransform::inc(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