标签:des style http color os io java ar strong
C++高精度问题太蛋疼了....
18 111 1111
1 17 2 10 3 10
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int LL;
LL n;
LL check(LL r)
{
LL low=2,high=n,mid,ret=-1;
while(low<=high)
{
mid=(low+high)/2;
if(((LL)(pow(mid*1.,r-1.))>n||(LL)(pow(mid*1.,r-1.))<0)
||(LL)(pow(mid*1.,r*1.))>n||(LL)(pow(mid*1.,r*1.))<0)
{
high=mid-1;
continue;
}
LL temp=mid*(1-(LL)(pow(mid*1.,r*1.)))/(1-mid);
if(temp<=n-1||temp<=n)
{
if(temp==n||temp==n-1) ret=mid;
low=mid+1;
}
else
{
high=mid-1;
}
}
return ret;
}
int main()
{
while(scanf("%I64d",&n)!=EOF)
{
LL R=1,K=n-1,ans=(1LL<<60);
for(LL r=2;r<40;r++)
{
LL k=check(r);
if(k==-1) continue;
if(ans>r*k)
{
R=r; K=k;
}
}
printf("%I64d %I64d\n",R,K);
}
return 0;
}
标签:des style http color os io java ar strong
原文地址:http://blog.csdn.net/ck_boss/article/details/39106329