結果

問題 No.546 オンリー・ワン
コンテスト
ユーザー nebukuro09
提出日時 2017-07-15 00:47:11
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 855 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 629 ms
コンパイル使用メモリ 100,024 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-05 16:30:28
合計ジャッジ時間 954 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(3011): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`
private typeof(T.init % T.init) gcdImpl(T)(T a, T b)
                                ^

ソースコード

diff #
raw source code

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