二分+枚舉
二分寫的好挫
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
#define LL __int64
#define INF ((LL)1<<60)
LL n,ans;
LL a,b;
LL fun(LL bi,LL r)
{
LL k=1;
LL tmp=0;
while(r--)
{
k*=bi;
tmp+=k;
}
return tmp;
}
void get(int len)
{
LL l=1,r=(LL)pow((double)n,1.0/len);//l=1 因爲我挫的二分查找寫法
if(r<2)//注意點
r=2;
LL mid;
LL tmp;
while(l<r-1)
{
mid=(l+r)/2;
LL tmp=fun(mid,len);
if(tmp>=n-1)
r=mid;
else
l=mid;
}
tmp=fun(r,len);
if(tmp==n-1||tmp==n)
{
if(ans>len*r)
{
ans=len*r;
a=len;
b=r;
}
}
}
int main()
{
while(cin>>n)
{
ans=INF;
a=b=1;
for(int len=2;len<=45;len++)
get(len);
if(ans!=INF)
cout<<a<<" "<<b<<endl;
else
cout<<1<<" "<<n-1<<endl;
}
return 0;
}