結果

問題 No.886 Direct
ユーザー beetbeet
提出日時 2019-09-14 07:57:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,025 ms / 4,000 ms
コード長 2,067 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 200,308 KB
実行使用メモリ 27,052 KB
最終ジャッジ日時 2023-09-18 16:47:32
合計ジャッジ時間 33,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 773 ms
26,908 KB
testcase_01 AC 758 ms
26,832 KB
testcase_02 AC 778 ms
26,784 KB
testcase_03 AC 784 ms
26,832 KB
testcase_04 AC 766 ms
26,776 KB
testcase_05 AC 800 ms
26,832 KB
testcase_06 AC 829 ms
26,948 KB
testcase_07 AC 871 ms
26,908 KB
testcase_08 AC 774 ms
26,948 KB
testcase_09 AC 759 ms
26,824 KB
testcase_10 AC 743 ms
26,780 KB
testcase_11 AC 809 ms
26,772 KB
testcase_12 AC 1,025 ms
26,872 KB
testcase_13 AC 898 ms
26,780 KB
testcase_14 AC 950 ms
26,796 KB
testcase_15 AC 841 ms
26,852 KB
testcase_16 AC 824 ms
26,772 KB
testcase_17 AC 751 ms
26,824 KB
testcase_18 AC 868 ms
26,828 KB
testcase_19 AC 810 ms
26,780 KB
testcase_20 AC 771 ms
26,952 KB
testcase_21 AC 740 ms
26,968 KB
testcase_22 AC 749 ms
26,776 KB
testcase_23 AC 807 ms
27,052 KB
testcase_24 AC 855 ms
26,804 KB
testcase_25 AC 841 ms
26,776 KB
testcase_26 AC 880 ms
26,788 KB
testcase_27 AC 822 ms
27,052 KB
testcase_28 AC 805 ms
26,772 KB
testcase_29 AC 771 ms
26,832 KB
testcase_30 AC 831 ms
26,968 KB
testcase_31 AC 837 ms
26,852 KB
testcase_32 AC 883 ms
26,832 KB
testcase_33 AC 897 ms
26,772 KB
testcase_34 AC 966 ms
26,888 KB
testcase_35 AC 826 ms
26,852 KB
権限があれば一括ダウンロードができます

ソースコード

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;}
};
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 = 3e6+100;
using M = Mint<int>;
M ys[MAX]={},xs[MAX]={};

signed main(){
  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;

  for(int i=1;i<MAX;i++){
    for(int j=i+i;j<MAX;j+=i){
      ys[i]+=ys[j];
      xs[i]+=xs[j];
    }
  }

  for(int i=0;i<MAX;i++) ys[i]*=xs[i];

  for(int i=MAX-1;i>=1;i--){
    for(int j=i+i;j<MAX;j+=i){
      ys[i]-=ys[j];
      xs[i]-=xs[j];
    }
  }

  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;
}
0