結果

問題 No.546 オンリー・ワン
ユーザー nebukuro09nebukuro09
提出日時 2017-07-15 00:47:11
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 103,016 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 15:16:36
合計ジャッジ時間 1,410 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

long MAX = 10 ^^ 9 + 10;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto L = s[1];
    auto H = s[2];
    auto C = readln.split.map!(to!int).array;

    auto cnt = new long[](N+1);

    foreach (mask; 0..(1 << N)) {
        long tmp = 0;
        long lcm = 1;
        foreach (i; 0..N) {
            if (mask & (1 << i)) lcm = lcm == 1 ? C[i] : lcm * C[i] / gcd(lcm, C[i]);
            lcm = min(lcm, MAX);
        }
        //if (mask.popcnt <= 1) continue;
        cnt[mask.popcnt] += H / lcm - (L - 1) / lcm;
    }

    long tmp1 = 0;
    foreach (i; 1..N+1) tmp1 += (i % 2) ? cnt[i]*i : -cnt[i]*i;

    tmp1.writeln;
}
0