結果

問題 No.376 立方体のN等分 (2)
ユーザー te-shte-sh
提出日時 2017-07-24 13:58:24
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 89,544 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-09-03 15:24:23
合計ジャッジ時間 3,614 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 17 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 6 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 5 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 147 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 187 ms
4,376 KB
testcase_32 AC 75 ms
4,380 KB
testcase_33 AC 105 ms
4,380 KB
testcase_34 AC 156 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 209 ms
4,384 KB
testcase_37 AC 208 ms
4,380 KB
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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