結果

問題 No.1627 三角形の成立
ユーザー saksak
提出日時 2021-07-16 20:48:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 1,000 ms
コード長 3,212 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 203,920 KB
実行使用メモリ 162,540 KB
最終ジャッジ日時 2023-09-25 20:51:38
合計ジャッジ時間 10,970 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
162,336 KB
testcase_01 AC 315 ms
162,372 KB
testcase_02 AC 310 ms
162,292 KB
testcase_03 AC 312 ms
162,472 KB
testcase_04 AC 314 ms
162,532 KB
testcase_05 AC 316 ms
162,420 KB
testcase_06 AC 315 ms
162,284 KB
testcase_07 AC 315 ms
162,304 KB
testcase_08 AC 314 ms
162,288 KB
testcase_09 AC 314 ms
162,300 KB
testcase_10 AC 315 ms
162,248 KB
testcase_11 AC 316 ms
162,540 KB
testcase_12 AC 314 ms
162,360 KB
testcase_13 AC 315 ms
162,540 KB
testcase_14 AC 312 ms
162,296 KB
testcase_15 AC 313 ms
162,284 KB
testcase_16 AC 313 ms
162,376 KB
testcase_17 AC 314 ms
162,172 KB
testcase_18 AC 314 ms
162,316 KB
testcase_19 AC 312 ms
162,472 KB
testcase_20 AC 312 ms
162,212 KB
testcase_21 AC 314 ms
162,184 KB
testcase_22 AC 314 ms
162,380 KB
testcase_23 AC 312 ms
162,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

const ll MOD = pow(10,9)+7;
struct MLL {
  ll x, mod;
  MLL(ll y=0, ll m=MOD) { x = y; mod = m; }

  MLL &operator+= (const MLL &p) { x = (x+p.x)%mod;       return *this; }
  MLL &operator-= (const MLL &p) { x = (x-p.x+mod)%mod;   return *this; }
  MLL &operator*= (const MLL &p) { x = (x*p.x)%mod;       return *this; }
  MLL &operator/= (const MLL &p) { x = (x*p.inv().x)%mod; return *this; }
  MLL  operator+  (const MLL &p) const { return MLL(*this)+=p; }
  MLL  operator-  (const MLL &p) const { return MLL(*this)-=p; }
  MLL  operator*  (const MLL &p) const { return MLL(*this)*=p; }
  MLL  operator/  (const MLL &p) const { return MLL(*this)/=p; }
  bool operator== (const MLL &p) const { return x==p.x; }
  bool operator!= (const MLL &p) const { return x!=p.x; }
  bool operator<  (const MLL &p) const { return x< p.x; }
  bool operator<= (const MLL &p) const { return x<=p.x; }
  bool operator>  (const MLL &p) const { return x> p.x; }
  bool operator>= (const MLL &p) const { return x>=p.x; }
  MLL pow(MLL n) const { MLL result(1), p(x); ll tn = n.x; while(tn){ if (tn&1) result*=p; p*=p; tn>>=1; } return result; }
  MLL inv() const { return pow(MOD-2); }
};

MLL operator+ (ll x, MLL p) { return (MLL)x+p; }
MLL operator- (ll x, MLL p) { return (MLL)x-p; }
MLL operator* (ll x, MLL p) { return (MLL)x*p; }
MLL operator/ (ll x, MLL p) { return (MLL)x/p; }

vector<MLL> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x); rep(i,x) fac[i] = i ? fac[i-1]*i : 1; }
MLL nck(MLL n, MLL k) { return fac[n.x]/(fac[k.x]*fac[(n-k).x]); };

ostream &operator<< (ostream &ost, const MLL &p) { return ost << p.x; }
istream &operator>> (istream &ist, MLL &p) { return ist >> p.x; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

ll MA = 2*pow(10,5)+10;

int main() {
  c_fac();
  MLL n, m; cin >> n >> m;
  assert(1<=n.x&&n.x<=2*pow(10,5));
  assert(1<=m.x&&m.x<=2*pow(10,5));
  MLL cnt[MA] = {};
  repr(i,1,MA) {
    MLL cn = (n.x/i) * (2*n-i*(n.x/i+1)) / 2;
    MLL cm = (m.x/i) * (2*m-i*(m.x/i+1)) + m;
    cnt[i] = cn*cm;
  }
  // debug(cnt,cnt+10);
  for (ll i=MA-1; i>0; i--) for (ll j=2; i*j<MA; j++) cnt[i] -= cnt[i*j];
  // debug(cnt,cnt+10);

  MLL result = 0;
  if (n>=3) {
    result += nck(n,3) * m.pow(3);
    repr(i,1,MA) result -= cnt[i]*(i-1);
  }
  if (m>=2) result += n*(n-1)*nck(m,2)*m;
  cout << result << endl;

  return 0;
}
0