結果
問題 | No.886 Direct |
ユーザー | QCFium |
提出日時 | 2019-08-20 16:19:12 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 889 ms / 4,000 ms |
コード長 | 1,547 bytes |
コンパイル時間 | 2,312 ms |
コンパイル使用メモリ | 77,972 KB |
実行使用メモリ | 79,384 KB |
最終ジャッジ日時 | 2024-04-16 02:27:18 |
合計ジャッジ時間 | 15,290 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 140 ms
41,108 KB |
testcase_01 | AC | 142 ms
41,324 KB |
testcase_02 | AC | 137 ms
41,316 KB |
testcase_03 | AC | 147 ms
42,000 KB |
testcase_04 | AC | 140 ms
41,544 KB |
testcase_05 | AC | 139 ms
41,296 KB |
testcase_06 | AC | 138 ms
41,416 KB |
testcase_07 | AC | 139 ms
41,356 KB |
testcase_08 | AC | 140 ms
41,232 KB |
testcase_09 | AC | 139 ms
41,108 KB |
testcase_10 | AC | 144 ms
41,116 KB |
testcase_11 | AC | 141 ms
41,268 KB |
testcase_12 | AC | 139 ms
41,128 KB |
testcase_13 | AC | 138 ms
41,392 KB |
testcase_14 | AC | 143 ms
41,020 KB |
testcase_15 | AC | 142 ms
41,264 KB |
testcase_16 | AC | 139 ms
41,308 KB |
testcase_17 | AC | 142 ms
41,880 KB |
testcase_18 | AC | 186 ms
45,280 KB |
testcase_19 | AC | 165 ms
43,536 KB |
testcase_20 | AC | 150 ms
42,040 KB |
testcase_21 | AC | 195 ms
45,636 KB |
testcase_22 | AC | 182 ms
45,408 KB |
testcase_23 | AC | 294 ms
49,768 KB |
testcase_24 | AC | 498 ms
61,964 KB |
testcase_25 | AC | 385 ms
53,944 KB |
testcase_26 | AC | 276 ms
48,704 KB |
testcase_27 | AC | 835 ms
76,488 KB |
testcase_28 | AC | 566 ms
64,100 KB |
testcase_29 | AC | 138 ms
41,220 KB |
testcase_30 | AC | 883 ms
79,324 KB |
testcase_31 | AC | 869 ms
79,384 KB |
testcase_32 | AC | 875 ms
79,044 KB |
testcase_33 | AC | 889 ms
79,260 KB |
testcase_34 | AC | 889 ms
79,280 KB |
testcase_35 | AC | 888 ms
79,284 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); } }