結果

問題 No.886 Direct
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2019-09-28 15:10:57
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,156 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 29,140 KB
実行使用メモリ 13,648 KB
最終ジャッジ日時 2023-07-25 14:10:37
合計ジャッジ時間 9,725 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
13,564 KB
testcase_01 AC 162 ms
13,440 KB
testcase_02 AC 161 ms
13,584 KB
testcase_03 AC 162 ms
13,632 KB
testcase_04 AC 161 ms
13,512 KB
testcase_05 AC 162 ms
13,640 KB
testcase_06 AC 161 ms
13,644 KB
testcase_07 AC 164 ms
13,440 KB
testcase_08 AC 159 ms
13,500 KB
testcase_09 AC 163 ms
13,644 KB
testcase_10 AC 161 ms
13,648 KB
testcase_11 AC 162 ms
13,436 KB
testcase_12 AC 163 ms
13,596 KB
testcase_13 AC 161 ms
13,576 KB
testcase_14 AC 159 ms
13,512 KB
testcase_15 AC 160 ms
13,648 KB
testcase_16 AC 159 ms
13,640 KB
testcase_17 AC 161 ms
13,556 KB
testcase_18 AC 163 ms
13,544 KB
testcase_19 AC 161 ms
13,640 KB
testcase_20 AC 162 ms
13,644 KB
testcase_21 AC 160 ms
13,532 KB
testcase_22 AC 160 ms
13,508 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 160 ms
13,616 KB
testcase_30 AC 160 ms
13,548 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define N 3000000

/*
\sum_{a,b,gcd(a,b)=1} (h-a)(w-b)
f(n) := \sum_{a,b,gcd(a,b)=n} (h-a)(w-b)

F(m) := \sum_{a,b,m|gcd(a,b)} (h-a)(w-b)
= \sum_{a,m|a}(h-a) \sum_{b,m|b}(w-b)
= [h floor(h/m) - m S(floor(h/m))][w floor(w/m) - m S(floor(w/m))]

f(1) = \sum_{m} mu(m) F(m)
*/

const int mod = 1000000007;
int h, w;

long long int S(int n){
  return (long long) n * (n+1) / 2;
}

int F(int m){
  long long a = (long long) h/m*h - (long long) m * S(h/m);
  long long b = (long long) w/m*w - (long long) m * S(w/m);
  return (a % mod) * (b % mod) % mod;
}

int mu[N+1];

int main(){
  int i, j, z;

  mu[1] = 1;
  for(i=2;i<=N;i++){
    if(!mu[i]){
      for(j=2*i;j<=N;j+=i){
        mu[j] = mu[j]?-mu[j]:-1;
      }
    }
  }
  for(i=N;i>=1;i--){
    if(!mu[i]){
      mu[i] = -1;
      if((long long) i*i > N) continue;
      for(j=i*i;j<=N;j+=i*i){
        mu[j] = 0;
      }
    }
  }

  scanf("%d%d",&h,&w);
  z = 0;
  for(i=1;i<=N;i++){
    z += mu[i] * F(i);
    if(z >= mod) z -= mod;
    if(z < 0)    z += mod;
  }
  z += z;
  z += ((long long) (w-1) * h + (long long) (h-1) * w);
  z %= mod;
  printf("%d\n", z);
  
  return 0;
}
0