結果
問題 | No.546 オンリー・ワン |
ユーザー | tanzaku |
提出日時 | 2017-07-14 22:38:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 830 bytes |
コンパイル時間 | 3,774 ms |
コンパイル使用メモリ | 78,376 KB |
実行使用メモリ | 41,436 KB |
最終ジャッジ日時 | 2024-04-16 20:25:06 |
合計ジャッジ時間 | 5,905 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
41,180 KB |
testcase_01 | AC | 137 ms
40,796 KB |
testcase_02 | AC | 136 ms
41,360 KB |
testcase_03 | AC | 133 ms
41,424 KB |
testcase_04 | AC | 138 ms
41,096 KB |
testcase_05 | AC | 136 ms
41,164 KB |
testcase_06 | AC | 135 ms
41,040 KB |
testcase_07 | AC | 139 ms
41,436 KB |
testcase_08 | AC | 142 ms
41,268 KB |
testcase_09 | AC | 143 ms
41,384 KB |
testcase_10 | AC | 141 ms
41,120 KB |
ソースコード
import java.util.*; public class No546 { public static void main(String[] args) { try (final Scanner sc = new Scanner(System.in)) { int n = sc.nextInt(); int l = sc.nextInt(); int h = sc.nextInt(); int[] xs = new int[n]; for (int i = 0; i < n; i++) { xs[i] = sc.nextInt(); } long ans = 0; for (int i = 1; i < 1<<n; i++) { long x = 1; int s = -1; for (int j = 0; j < n; j++) if ((i>>>j&1)==1) { x = lcm(x, xs[j]); if (x > h) x = h + 1; s = -s; } ans += Integer.bitCount(i) * s * (h/x - (l-1)/x); } System.out.println(ans); } } static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n % r); } static long lcm(long n, long r) { return n/gcd(n,r)*r; } static void dump(Object... objects) { System.err.println(Arrays.deepToString(objects)); } }