結果

問題 No.376 立方体のN等分 (2)
ユーザー mudbdbmudbdb
提出日時 2016-06-06 18:45:55
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 110 ms / 5,000 ms
コード長 1,732 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 26,440 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 20:22:03
合計ジャッジ時間 3,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 98 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 99 ms
4,384 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 102 ms
4,380 KB
testcase_24 AC 96 ms
4,380 KB
testcase_25 AC 0 ms
4,380 KB
testcase_26 AC 110 ms
4,376 KB
testcase_27 AC 37 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 0 ms
4,380 KB
testcase_31 AC 11 ms
4,380 KB
testcase_32 AC 37 ms
4,376 KB
testcase_33 AC 53 ms
4,376 KB
testcase_34 AC 26 ms
4,380 KB
testcase_35 AC 27 ms
4,376 KB
testcase_36 AC 52 ms
4,380 KB
testcase_37 AC 52 ms
4,380 KB
testcase_38 AC 15 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
// (2^3)^14 < 10^14 < (2^4)^14
long long P[4*14];
int E[4*14];
int Pend = 0;
int factor(long long N)
{
  long long p;
  int e;
  p=2;
  if (N%p == 0) {
    P[Pend] = p;
    e=1;
    for (N/=p; N%p==0; N/=p) e++;
    E[Pend] = e;
    Pend++;
  }
  for (p=3; p*p<=N; p+=2) {
    if (N%p == 0) {
      P[Pend] = p;
      e=1;
      for (N/=p; N%p==0; N/=p) e++;
      E[Pend] = e;
      Pend++;
    }
  }
  if (N != 1) {
    P[Pend] = N;
    E[Pend] = 1;
    Pend++;
  }
  return 0;
}
long long pwr(long long d, int e)
{
  long long dd = 1;
  if (e == 0) {
  } else {
    int i;
    for (i=1; i<=e; i++) dd*=d;
  }
  return dd;
}
int cmpr(const void *a, const void *b)
{
  if (*(long long *)a < *(long long *)b) {
    return -1;
  } else if (*(long long *)a > *(long long *)b) {
    return 1;
  } else {
    return 0;
  }
}
int main()
{
  long long N;
  scanf("%lld", &N);
  factor(N);

  int i;
  long long *D;
  int Dsz = 1;
  for (i=0; i<Pend; i++) Dsz *= (E[i]+1);
  D = (long long *)malloc(sizeof(long long)*Dsz);
  for (i=0; i<Dsz; i++) D[i] = 1;

  int j,k,l;
  int rpt = 1;
  for (i=0; i<Pend; i++) {
    for (j=0, k=0; j<Dsz; ) {
      for (l=0; l<rpt; l++) {
        D[j] *= pwr(P[i],k);
        j++;
      }
      k++;
      k %= (E[i]+1);
    }
    rpt *= (E[i]+1);
  }
  qsort(D, Dsz, sizeof(long long), cmpr);

  long long N2;
  long long a,b,c;
  long long min = N-1;
  i = 0;
  for (a=D[i]; (a<=100000) && (a*a*a<=N); a=D[i]) {
    N2 = N/a;
    j = 0;
    for (b=D[j]; (b<=10000000) && (b*b<=N2); b=D[j]) {
      if (N2%b == 0) {
        c = N2/b;
        if (min > (a+b+c-3)) min = a+b+c-3;
      }
      j++;
    }
    i++;
  }
  printf("%lld %lld\n", min, N-1);
  return 0;
}
0