結果
問題 | No.1664 Unstable f(n) |
ユーザー | merlin |
提出日時 | 2021-09-03 21:51:49 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 1,875 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 74,132 KB |
実行使用メモリ | 51,872 KB |
最終ジャッジ日時 | 2023-08-21 21:19:57 |
合計ジャッジ時間 | 6,108 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
50,140 KB |
testcase_01 | AC | 50 ms
50,188 KB |
testcase_02 | AC | 49 ms
50,156 KB |
testcase_03 | AC | 49 ms
50,020 KB |
testcase_04 | AC | 49 ms
50,120 KB |
testcase_05 | AC | 48 ms
50,132 KB |
testcase_06 | AC | 48 ms
50,252 KB |
testcase_07 | AC | 48 ms
50,212 KB |
testcase_08 | AC | 48 ms
50,044 KB |
testcase_09 | AC | 48 ms
50,396 KB |
testcase_10 | AC | 48 ms
51,068 KB |
testcase_11 | AC | 63 ms
50,412 KB |
testcase_12 | AC | 72 ms
51,784 KB |
testcase_13 | AC | 73 ms
51,380 KB |
testcase_14 | AC | 71 ms
51,716 KB |
testcase_15 | AC | 70 ms
51,492 KB |
testcase_16 | AC | 72 ms
50,448 KB |
testcase_17 | AC | 73 ms
50,184 KB |
testcase_18 | AC | 75 ms
51,680 KB |
testcase_19 | AC | 75 ms
50,352 KB |
testcase_20 | AC | 72 ms
51,872 KB |
testcase_21 | AC | 50 ms
49,900 KB |
testcase_22 | AC | 50 ms
50,152 KB |
testcase_23 | AC | 49 ms
50,252 KB |
testcase_24 | AC | 50 ms
51,244 KB |
testcase_25 | AC | 50 ms
50,344 KB |
testcase_26 | AC | 49 ms
50,584 KB |
testcase_27 | AC | 48 ms
50,104 KB |
testcase_28 | AC | 48 ms
50,112 KB |
testcase_29 | AC | 49 ms
49,968 KB |
testcase_30 | AC | 49 ms
50,156 KB |
testcase_31 | AC | 49 ms
50,388 KB |
testcase_32 | AC | 53 ms
51,228 KB |
testcase_33 | AC | 51 ms
50,152 KB |
testcase_34 | AC | 49 ms
50,152 KB |
testcase_35 | AC | 71 ms
51,416 KB |
testcase_36 | AC | 50 ms
50,952 KB |
testcase_37 | AC | 71 ms
50,364 KB |
testcase_38 | AC | 49 ms
50,984 KB |
testcase_39 | AC | 54 ms
50,284 KB |
testcase_40 | AC | 62 ms
51,684 KB |
ソースコード
import java.io.*; import java.math.BigInteger; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); long n=Long.parseLong(bu.readLine()); int i; long r=root(n),ans=Math.min(n,r+(n-r*r)+2); //System.out.println(ans); for(i=3;i<63;i++) { int j=2; if(i<20) { long ti=power(j,i); while(ti<=n) { ans=Math.min(ans,n-ti+i+j); j++; ti=power(j,i); } } else { BigInteger ti=big_power(j,i),en=BigInteger.valueOf(n); while(ti.compareTo(en)<=0) { ans=Math.min(ans,en.subtract(ti).longValue()+i+j); j++; ti=big_power(j,i); } } //System.out.println(i+" "+j); } System.out.print(ans); } static long root(long n) { long l=1,r=(int)1e9,ans=l,mid; while(l<=r) { mid=(l+r)>>1; if(mid*mid<=n) { ans=mid; l=mid+1; } else r=mid-1; } return ans; } static long power(long a,int b) { long res=1; while(b!=0) { if(b%2==1) res=res*a; b>>=1; a=a*a; } return res; } static BigInteger big_power(int a,int b) { BigInteger res=new BigInteger("1"); while(b!=0) { res=res.multiply(res.valueOf(a)); b--; } return res; } }