結果

問題 No.546 オンリー・ワン
ユーザー nebukuro09
提出日時 2017-07-15 00:47:11
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 116,352 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 20:59:53
合計ジャッジ時間 1,469 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/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