結果
問題 | No.546 オンリー・ワン |
ユーザー |
![]() |
提出日時 | 2017-07-14 23:17:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 1,339 bytes |
コンパイル時間 | 2,132 ms |
コンパイル使用メモリ | 77,104 KB |
実行使用メモリ | 41,756 KB |
最終ジャッジ日時 | 2024-10-07 23:32:13 |
合計ジャッジ時間 | 4,510 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int N = sc.nextInt();long L = sc.nextLong();long H = sc.nextLong();long[] c = new long[N];for(int i = 0; i < N; i++) {c[i] = sc.nextLong();}long ans = 0;for(int i = 0; i < N; i++) {// c[i]のみで割れる個数を求めるlong t = H / c[i] - (L - 1) / c[i];long k = 0;for(int j = 1; j < (int)Math.pow(2, N); j++) {int count = 0;boolean flg = false;boolean over = true;long baisuu = 1;for(int l = 0; l < N; l++) {if((j & (1 << l)) != 0) {if(l == i) flg = true;count++;long g = gcd(baisuu, c[l]);baisuu *= (c[l] / g);if(baisuu > (long)Math.pow(10, 9)) {over = false;break;}}}if(over && flg && count > 1) {if(count % 2 == 1) {k -= (H / baisuu - (L - 1) / baisuu);} else {k += (H / baisuu - (L - 1) / baisuu);}}}ans += (t - k);}System.out.println(ans);}public static long gcd(long a, long b) {if(b == 0) return a;return gcd(b, a % b);}}