結果

問題 No.376 立方体のN等分 (2)
ユーザー mudbdbmudbdb
提出日時 2016-06-06 02:49:09
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 209 ms / 5,000 ms
コード長 1,995 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 22,912 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 13:49:51
合計ジャッジ時間 2,756 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 0 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 0 ms
6,944 KB
testcase_05 AC 0 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 0 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 16 ms
6,944 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 197 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 192 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 192 ms
6,944 KB
testcase_24 AC 187 ms
6,944 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 209 ms
6,944 KB
testcase_27 AC 34 ms
6,940 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 10 ms
6,944 KB
testcase_32 AC 33 ms
6,944 KB
testcase_33 AC 46 ms
6,940 KB
testcase_34 AC 24 ms
6,944 KB
testcase_35 AC 23 ms
6,940 KB
testcase_36 AC 47 ms
6,940 KB
testcase_37 AC 48 ms
6,944 KB
testcase_38 AC 13 ms
6,940 KB
testcase_39 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:58:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |   scanf("%lld", &N);
      |   ^~~~~~~~~~~~~~~~~

ソースコード

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;
  //for (i=0; i<Pend; i++) printf("%lld^%d ", P[i], E[i]);
  //printf("\n--\n");

  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);
  //for (i=0; i<Dsz; i++) printf("%lld\n", D[i]);

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