結果

問題 No.1664 Unstable f(n)
ユーザー mtrh
提出日時 2021-09-18 18:33:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 167,536 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 16:21:08
合計ジャッジ時間 2,607 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

ll mypow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1){
            res=res*x;
        }
        x=x*x;
        n>>=1;
    }
    return res;
}

int main(){
    ll N;
    cin>>N;
    ll ans=N;
    ll j=2;
    while(mypow(2,j)<=N){
        ll left=0,right=pow(N,(long double)1/j)+1;
        while(right-left>1){
            ll mid=left+(right-left)/2;
            if(mypow(mid,j)>N){
                right=mid;
            }else{
                left=mid;
            }
        }
        ans=min(ans,left+j+N-mypow(left,j));
        j++;
    }
    cout<<ans<<endl;
    return 0;
}
0