結果

問題 No.376 立方体のN等分 (2)
ユーザー te-sh
提出日時 2017-07-24 13:58:24
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 102,572 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 21:06:59
合計ジャッジ時間 3,167 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = readln.chomp.to!long;

  auto calcP(long n)
  {
    foreach_reverse (p; 1..ncbrt(n)*2)
      if (n % p == 0) return p;
    assert(0);
  }

  auto calcQ(long n)
  {
    foreach_reverse (q; 1..nsqrt(n)*2)
      if (n % q == 0) return q;
    assert(0);
  }

  auto p = calcP(n);
  auto q = calcQ(n/p);
  auto r = n/p/q;
  writeln(p + q + r - 3, " ", n - 1);
}

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;
}

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