結果

問題 No.886 Direct
ユーザー beetbeet
提出日時 2019-09-13 22:30:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 882 ms / 4,000 ms
コード長 2,889 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 198,964 KB
実行使用メモリ 167,700 KB
最終ジャッジ日時 2023-09-17 14:49:59
合計ジャッジ時間 31,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 730 ms
167,392 KB
testcase_01 AC 720 ms
167,400 KB
testcase_02 AC 717 ms
167,388 KB
testcase_03 AC 714 ms
167,440 KB
testcase_04 AC 728 ms
167,448 KB
testcase_05 AC 723 ms
167,448 KB
testcase_06 AC 728 ms
167,392 KB
testcase_07 AC 724 ms
167,448 KB
testcase_08 AC 720 ms
167,512 KB
testcase_09 AC 715 ms
167,400 KB
testcase_10 AC 709 ms
167,388 KB
testcase_11 AC 713 ms
167,700 KB
testcase_12 AC 731 ms
167,400 KB
testcase_13 AC 727 ms
167,444 KB
testcase_14 AC 716 ms
167,460 KB
testcase_15 AC 721 ms
167,472 KB
testcase_16 AC 724 ms
167,464 KB
testcase_17 AC 718 ms
167,460 KB
testcase_18 AC 726 ms
167,456 KB
testcase_19 AC 723 ms
167,596 KB
testcase_20 AC 720 ms
167,596 KB
testcase_21 AC 722 ms
167,388 KB
testcase_22 AC 726 ms
167,524 KB
testcase_23 AC 751 ms
167,600 KB
testcase_24 AC 804 ms
167,396 KB
testcase_25 AC 760 ms
167,392 KB
testcase_26 AC 732 ms
167,588 KB
testcase_27 AC 862 ms
167,524 KB
testcase_28 AC 815 ms
167,464 KB
testcase_29 AC 715 ms
167,516 KB
testcase_30 AC 881 ms
167,448 KB
testcase_31 AC 882 ms
167,512 KB
testcase_32 AC 878 ms
167,396 KB
testcase_33 AC 875 ms
167,604 KB
testcase_34 AC 876 ms
167,444 KB
testcase_35 AC 876 ms
167,388 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;}

  // 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 = 7e6+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