結果
問題 | No.886 Direct |
ユーザー | QCFium |
提出日時 | 2019-08-20 16:19:12 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 671 ms / 4,000 ms |
コード長 | 1,547 bytes |
コンパイル時間 | 2,542 ms |
コンパイル使用メモリ | 77,124 KB |
実行使用メモリ | 79,336 KB |
最終ジャッジ日時 | 2024-10-06 12:30:41 |
合計ジャッジ時間 | 12,716 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
40,972 KB |
testcase_01 | AC | 130 ms
41,116 KB |
testcase_02 | AC | 116 ms
40,684 KB |
testcase_03 | AC | 127 ms
41,896 KB |
testcase_04 | AC | 108 ms
40,156 KB |
testcase_05 | AC | 126 ms
41,452 KB |
testcase_06 | AC | 107 ms
39,660 KB |
testcase_07 | AC | 128 ms
40,916 KB |
testcase_08 | AC | 121 ms
41,240 KB |
testcase_09 | AC | 123 ms
41,052 KB |
testcase_10 | AC | 124 ms
41,316 KB |
testcase_11 | AC | 119 ms
41,096 KB |
testcase_12 | AC | 126 ms
41,196 KB |
testcase_13 | AC | 125 ms
41,084 KB |
testcase_14 | AC | 123 ms
41,076 KB |
testcase_15 | AC | 124 ms
41,120 KB |
testcase_16 | AC | 124 ms
41,144 KB |
testcase_17 | AC | 126 ms
41,708 KB |
testcase_18 | AC | 151 ms
45,332 KB |
testcase_19 | AC | 148 ms
43,740 KB |
testcase_20 | AC | 111 ms
40,696 KB |
testcase_21 | AC | 158 ms
45,084 KB |
testcase_22 | AC | 169 ms
44,900 KB |
testcase_23 | AC | 261 ms
49,592 KB |
testcase_24 | AC | 431 ms
61,700 KB |
testcase_25 | AC | 331 ms
53,776 KB |
testcase_26 | AC | 243 ms
48,692 KB |
testcase_27 | AC | 637 ms
76,404 KB |
testcase_28 | AC | 455 ms
63,712 KB |
testcase_29 | AC | 118 ms
41,116 KB |
testcase_30 | AC | 656 ms
78,972 KB |
testcase_31 | AC | 671 ms
79,336 KB |
testcase_32 | AC | 657 ms
79,228 KB |
testcase_33 | AC | 655 ms
79,172 KB |
testcase_34 | AC | 662 ms
79,196 KB |
testcase_35 | AC | 666 ms
79,328 KB |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { final int MOD = 1000000007; Scanner scanner = new Scanner(System.in); int h = scanner.nextInt(); int w = scanner.nextInt(); int[] div_by = new int[w]; int[] div_to = new int[w]; for (int i = 2; i < w; i++) if (div_by[i] == 0) for (int j = 2; j <= (w - 1) / i; j++) { div_by[i * j] = i; div_to[i * j] = j; } long res = ((long) h * (w - 1) + (long) w * (h - 1)) % MOD; for (int i = 1; i < w; i++) { int[] facts = new int[30]; int n_fact = 0; for (int cur = i; ; ) { if (div_by[cur] == 0) { if (cur > 1) facts[n_fact++] = cur; break; } facts[n_fact++] = div_by[cur]; cur = div_to[cur]; } // facts should be sorted in descending order here if (n_fact != 0) { int head = 0; for (int j = 1; j < n_fact; j++) if (facts[j] != facts[head]) facts[++head] = facts[j]; n_fact = head + 1; } int[] prod = new int[1 << n_fact]; for (int j = 0; j < n_fact; j++) prod[1 << j] = facts[j]; prod[0] = 1; long so_num = 0, so_sum = 0; for (int j = 0; j < 1 << n_fact; j++) { int cur = prod[j] = prod[j & j - 1] * prod[j & ~(j - 1)]; int num = (h - 1) / cur; long sum = (long) num * (num + 1) / 2 * cur; if ((Integer.bitCount(j) & 1) != 0) { so_num -= num; so_sum -= sum; } else { so_num += num; so_sum += sum; } } res = (res + (long)(2 * (w - i)) * ((so_num * h - so_sum) % MOD)) % MOD; } System.out.println(res); } }