結果
| 問題 | 
                            No.546 オンリー・ワン
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tanzaku
                         | 
                    
| 提出日時 | 2017-07-14 22:38:11 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 130 ms / 2,000 ms | 
| コード長 | 830 bytes | 
| コンパイル時間 | 3,391 ms | 
| コンパイル使用メモリ | 77,464 KB | 
| 実行使用メモリ | 54,144 KB | 
| 最終ジャッジ日時 | 2024-10-07 23:15:21 | 
| 合計ジャッジ時間 | 5,678 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
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)); }
}
            
            
            
        
            
tanzaku