結果

問題 No.473 和と積の和
ユーザー yosupotyosupot
提出日時 2016-12-24 16:45:26
言語 D
(dmd 2.106.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,104 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 89,820 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-03 00:07:38
合計ジャッジ時間 3,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,568 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 23 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 142 ms
4,376 KB
testcase_26 AC 14 ms
4,376 KB
testcase_27 AC 25 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 116 ms
4,384 KB
testcase_35 AC 121 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 116 ms
4,384 KB
testcase_39 AC 72 ms
4,380 KB
testcase_40 AC 81 ms
4,380 KB
testcase_41 AC 78 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 9 ms
4,376 KB
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/+ dub.sdl:
	name "A"
	dependency "dcomp" version=">=0.0.2"
+/
import std.stdio, std.conv, std.algorithm;
// import dcomp.scanner;
// import dcomp.prime;

Scanner sc;
static this() {sc = new Scanner();}

int[] divlist;

int calc(int N, int X, int bc) {
    if (N == 0) {
        if (X == 1) return 1;
        return 0;
    }
    if (N == 1) {
        if (bc <= X) return 1;
        return 0;
    }
    int B = divlist[bc];
    if (bc == divlist.length.to!int) return 0;
    if (B*B > X) return 0;
    int ans = calc(N, X, bc+1);
    if (X % B == 0) {
        ans += calc(N-1, X/B, bc);
    }
    return ans;
}

int main() {
    int N, X;
    sc.read(N, X);
    X++;
    divlist = factorList(X);

    writeln(calc(N, X, 1));
	return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/prime.d */
// module dcomp.prime;

T[] factorList(T)(T x) {
    import std.algorithm : sort;
    T[] res;
    for (int i = 1; i*i <= x; i++) {
        if (x%i == 0) {
            res ~= i;
            if (i*i != x) res ~= x/i;
        }
    }
    sort(res);
    return res;
}
0