結果

問題 No.473 和と積の和
ユーザー te-sh
提出日時 2017-12-12 14:39:15
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 255 ms / 3,000 ms
コード長 607 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 102,724 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 23:01:41
合計ジャッジ時間 3,656 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], x = rd[1];

  long calc(int n, int x, int m)
  {
    if (x < m) return 0;
    if (n == 1) return 1;

    auto r = 0L;
    foreach (i; m..x.nsqrt+1) {
      if (x % i == 0)
        r += calc(n-1, x/i, i);
    }

    return r;
  }

  writeln(calc(n, x+1, 2));
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = 1 << (n.bsr / 2 + 1);
  return iota(1, m).map!"a * a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}
0