結果

問題 No.546 オンリー・ワン
ユーザー tanzakutanzaku
提出日時 2017-07-14 22:38:11
言語 Java19
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 3,149 ms
コンパイル使用メモリ 74,708 KB
実行使用メモリ 57,708 KB
最終ジャッジ日時 2023-07-29 14:32:38
合計ジャッジ時間 5,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,808 KB
testcase_01 AC 120 ms
55,764 KB
testcase_02 AC 120 ms
55,456 KB
testcase_03 AC 120 ms
55,924 KB
testcase_04 AC 120 ms
56,252 KB
testcase_05 AC 121 ms
56,040 KB
testcase_06 AC 123 ms
57,708 KB
testcase_07 AC 124 ms
55,916 KB
testcase_08 AC 124 ms
56,204 KB
testcase_09 AC 125 ms
56,320 KB
testcase_10 AC 127 ms
56,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


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)); }
}
0