| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
poj的AC,0MS,UVA的却TLE#include<iostream>
#include<cmath>
using namespace std;
int main()
{
long long int m,n;
while(cin>>m>>n && m+n)
{
long long int i,j;
for(j=31;j>=1;j--)
{
if(n==1) {j=1;break;}
double t=pow(n*1.0,1.0/j*1.0);
//cout<<t<<endl;
if(pow((int(t+0.5))*1.0,j*1.0)==n) {j=int(t+0.5);break;}
}
//cout<<"j="<<j<<endl;
long long int temp=m;
long long int high=0,cat=1,catall=1;
while(temp!=1)
{
high+=temp*cat;
cat*=j;
catall+=cat;
temp/=(j+1);
}
high+=n;
cout<<catall-cat<<" "<<high<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator