結果

問題 No.375 立方体のN等分 (1)
ユーザー k
提出日時 2020-09-03 17:47:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 897 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 191,864 KB
最終ジャッジ日時 2025-01-14 04:14:42
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long long n;
  cin >> n;

  long long ret = n-1;

  // x * y = n, x <= y
  for (long long x = 2; x * x <= n; x++) {
    if (n % x) continue;
    long long y = n / x;
    if (x > 1 && y > 1)
      ret = min(ret, (x-1) + (y-1));
  }

  // x * y * z = n, x <= y <= z
  for (long long x = 2; x * x * x <= n; x++) {
    if (n % x) continue;
    long long n2 = n / x;
    for (long long y = 2; y * y <= n2; y++) {
      if (n2 % y) continue;
      long long z = n2 / y;
      if (x > 1 && y > 1 && z > 1)
        ret = min(ret, (x-1) + (y-1) + (z-1));
    }
  }
  
  cout << ret << " " << (n-1) << endl;
  
  return 0;
}
0