結果

問題 No.1664 Unstable f(n)
コンテスト
ユーザー mtrh
提出日時 2021-09-18 18:33:23
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 657 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,050 ms
コンパイル使用メモリ 184,764 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-20 21:04:30
合計ジャッジ時間 2,519 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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