結果
| 問題 |
No.546 オンリー・ワン
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-09-08 08:27:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,503 bytes |
| コンパイル時間 | 2,764 ms |
| コンパイル使用メモリ | 76,940 KB |
| 実行使用メモリ | 41,764 KB |
| 最終ジャッジ日時 | 2024-11-29 11:47:49 |
| 合計ジャッジ時間 | 4,510 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 WA * 1 |
ソースコード
import java.util.*;
public class Main {
static final int MAX = 1000000007;
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long left = sc.nextInt();
long right = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int[] lcms = new int[1 << n];
lcms[0] = 1;
long total = 0;
for (int i = 1; i < (1 << n); i++) {
int pop = getPopcount(i);
for (int j = 0; j < n; j++) {
if ((i & (1 << j)) != (1 << j)) {
continue;
}
lcms[i] = getLCM(lcms[i ^ (1 << j)], arr[j]);
break;
}
if (pop % 2 == 0) {
total -= (right / lcms[i] - (left - 1) / lcms[i]) * pop;
} else {
total += (right / lcms[i] - (left - 1) / lcms[i]) * pop;
}
}
System.out.println(total);
}
static int getLCM(int x, int y) {
int gcd = getGCD(x, y);
if (x / gcd >= MAX / y) {
return MAX;
} else {
return x / gcd * y;
}
}
static int getGCD(int x, int y) {
if (x % y == 0) {
return y;
} else {
return getGCD(y, x % y);
}
}
static int getPopcount(int x) {
int count = 0;
while(x > 0) {
count += x % 2;
x /= 2;
}
return count;
}
}
tenten