結果

問題 No.376 立方体のN等分 (2)
ユーザー Tsuneo Yoshioka
提出日時 2016-06-04 23:50:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4,668 ms / 5,000 ms
コード長 717 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 63,796 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-08 10:40:47
合計ジャッジ時間 29,539 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <climits>

using namespace std;
typedef long long ll;

int main(void){
    // Here your code !
    ll N;
    ll mi = LLONG_MAX;
    ll bestc = -1;
    cin >> N;
    for(ll a=1;a*a*a<=N;a++){
        if(N%a!=0){
            continue;
        }
        ll M = N/a;
        ll startb = a;
        if(bestc != -1){
            startb = M/bestc;
        }
        for(ll b=a;b*b<=M;b++){
            if(M%b!=0){
                continue;
            }
            ll c = M/b;
            ll total = (a-1)+(b-1)+(c-1);
            if(total < mi){
                bestc = c;
                mi = total;
            }
        }        
    }
    cout << mi << " " << N-1 << endl;
    return 0;
}
0