結果
問題 | No.546 オンリー・ワン |
ユーザー | htensai |
提出日時 | 2020-01-30 19:55:10 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,867 bytes |
コンパイル時間 | 2,091 ms |
コンパイル使用メモリ | 76,964 KB |
実行使用メモリ | 36,900 KB |
最終ジャッジ日時 | 2024-09-16 03:48:46 |
合計ジャッジ時間 | 3,309 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
import java.util.*;import java.io.*;public class Main {static int[] dp;public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));String[] first = br.readLine().split(" ", 3);int n = Integer.parseInt(first[0]);int low = Integer.parseInt(first[1]) - 1;int high = Integer.parseInt(first[2]);String[] line = br.readLine().split(" ", n);int[] base = new int[n];dp = new int[1 << n];for (int i = 0; i < n; i++) {base[i] = Integer.parseInt(line[i]);dp[1 << i] = base[i];}long total = 0;for (int i = 1; i < (1 << n); i++) {dp[i] = dfw(i);total += high / dp[i] * getCount(i);total -= low / dp[i] * getCount(i);}System.out.println(total);}static int getCount(int x) {int count = 0;while (x > 0) {count += (x & 1);x = x >> 1;}if (count % 2 == 0) {return -count;} else {return count;}}static int dfw(int key) {if (dp[key] != 0) {return dp[key];}int x = 1;while (true) {if ((x & key) == x) {return dp[key] = getLCM(dfw(x), dfw(key ^ x));}x = x << 1;}//return 0;}static int getLCM(int x, int y) {x /= gcd(x, y);if ((long) x * (long) y >= Integer.MAX_VALUE) {return Integer.MAX_VALUE;} else {return x * y;}}static int gcd(int x, int y) {if (x % y == 0) {return y;} else {return gcd(y, x % y);}}}