結果

問題 No.886 Direct
ユーザー 37zigen37zigen
提出日時 2019-09-14 00:32:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 70,536 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 15:41:28
合計ジャッジ時間 8,426 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 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 WA -
testcase_30 AC 1 ms
4,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>

const long long MOD=(long long)1e9 + 7;


long long pow(long long a, long long n) {
  long long ret=1;
  for (;n>0;n>>=1,a=a*a%MOD) {
    if (n%2==1) ret=ret*a%MOD;
  }
  return ret;
}

long long inv(long long a) {
  return pow(a, MOD-2);
}

// s + s+1 + s+2 + ... + t
long long sum1(long long s, long long t) {
  if (s>t) return 0;
  return (s+t)*(t-s+1)%MOD*inv(2)%MOD;
}

long long gcd(long long a, long long b) {
  if (a>b) return gcd(b, a);
  if (a==0) return b;
  return gcd(b%a, a);
}

int main() {
  int H, W;
  std::cin >> H >> W;
  long long ans=0;
  for (long long p=2;p<H;++p) {
    ans+=(H-p)*W%MOD*(W-2-(W-1)/p)%MOD;
    ans-=(H-p)*(sum1(2, W-1)-p*sum1(1, (W-1)/p)%MOD)%MOD;
    ans=(ans+MOD)%MOD;
  }
  ans=2*ans%MOD;
  ans+=(H-1)*(W-1)%MOD*(H+W-2)%MOD;//p!=0 && q!=0 && (p==1 || q==1)
  ans+=(H*(W-1)%MOD+W*(H-1)%MOD)%MOD;//p=0 || q=0
  ans=(ans%MOD+MOD)%MOD;
  std::cout << ans << std::endl;
}
0