This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub beet-aizu/library
// verification-helper: PROBLEM https://yukicoder.me/problems/3267 #include<bits/stdc++.h> using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/divisor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); 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; }
#line 1 "test/yukicoder/3267.test.cpp" // verification-helper: PROBLEM https://yukicoder.me/problems/3267 #include<bits/stdc++.h> using namespace std; #define call_from_test #line 1 "mod/mint.cpp" #line 3 "mod/mint.cpp" using namespace std; #endif //BEGIN CUT HERE 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;} //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif #line 1 "convolution/divisor.cpp" #line 3 "convolution/divisor.cpp" 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 //INSERT ABOVE HERE signed main(){ return 0; } #endif #line 9 "test/yukicoder/3267.test.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); 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; }