結果

問題 No.375 立方体のN等分 (1)
ユーザー akakimidori
提出日時 2017-06-07 11:42:54
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 12:40:25
合計ジャッジ時間 2,022 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:33:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   scanf("%lld",&n);
      |   ^~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

#define MIN(a,b) ((a)<(b)?(a):(b))

typedef long long int ln;

ln calc2(ln n,ln s){
  ln res=n-1;
  ln k=s;
  while(k*k<=n){
    if(n%k==0){
      res=MIN(res,k+n/k-2);
    }
    k++;
  }
  return res;
}

ln calc3(ln n){
  ln res=n-1;
  ln k=2;
  while(k*k<=n){
    if(n%k==0){
      res=MIN(res,k-1+calc2(n/k,k));
    }
    k++;
  }
  return res;
}

void run(void){
  ln n;
  scanf("%lld",&n);

  ln max=n-1;
  ln min=calc3(n);
  printf("%lld %lld\n",min,max);
  return;
}

int main(void){
  run();
  return 0;
}
0