結果

問題 No.886 Direct
ユーザー tempura_pptempura_pp
提出日時 2019-08-20 18:06:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 4,000 ms
コード長 794 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 168,584 KB
実行使用メモリ 63,156 KB
最終ジャッジ日時 2024-04-16 02:32:01
合計ジャッジ時間 6,585 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 120 ms
31,488 KB
testcase_24 AC 139 ms
34,284 KB
testcase_25 AC 71 ms
22,528 KB
testcase_26 AC 95 ms
28,544 KB
testcase_27 AC 317 ms
58,788 KB
testcase_28 AC 301 ms
57,072 KB
testcase_29 AC 349 ms
63,156 KB
testcase_30 AC 345 ms
63,028 KB
testcase_31 AC 345 ms
63,032 KB
testcase_32 AC 338 ms
63,024 KB
testcase_33 AC 339 ms
62,936 KB
testcase_34 AC 335 ms
63,032 KB
testcase_35 AC 351 ms
63,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod = 1e9+7;
int main(){
  ll h, w;
  cin>>h>>w;
  int n=max(h+1,w+1);
  vector<ll> cnt1(n), cnt2(n);
  for(int i=1;i<h;++i)cnt1[i]=h-i;
  for(int i=1;i<w;++i)cnt2[i]=w-i;
  vector<int> prime, isprime(n,1);
  for(int i=2;i<n;++i){
    if(!isprime[i])continue;
    prime.push_back(i);
    for(int j=2*i;j<n;j+=i){
      isprime[j]=false;
      }
    }
  for(auto p:prime){
    int m=(n-1)/p;
    for(int i=m;i>0;--i){
      (cnt1[i]+=cnt1[i*p])%=mod;
      (cnt2[i]+=cnt2[i*p])%=mod;
      }
    }
  for(int i=1;i<n;++i)(cnt1[i]*=cnt2[i])%=mod;
  for(auto p:prime){
    int m=(n-1)/p;
    for(int i=1;i<=m;++i){
      (cnt1[i]+=mod-cnt1[i*p])%=mod;
      }
    }
  cout<<(2*cnt1[1]+h*(w-1)+w*(h-1))%mod<<endl;
  }

  
0