开始的时候没看懂题目,放了几天又做的。思路很简单。就像树状家谱;一代代的计算!!
知道我这次卡在那了吗:
我真是各种卡啊这次我卡了if(特殊情况)
a啊啊啊啊啊啊啊
大粗心啊
特殊情况是1 1
不是1 0
没仔细考虑
各种错!
代码如下:
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int h, n, count = 0, H , toH;
while(cin>>h>>n)
{
count = 0;
H = h;
toH = 0;
if(!h&&!n)break;
if(h==1&&n==1)
{
cout<<"0 1"<<endl;
continue;
}
int i;
for(i=1; h != int(pow(1.0+pow(n,1.0/i),i)+0.1); i++);
int num = int(pow(n,(1.0/i))+0.1);
for(int j = 0; j <= i ; j++)
{
count+=pow(num,j);
toH+=H*pow(num,j);
H = int(H*(1.0/(num+1))+0.1);
}
count-=n;
cout<<count<<" "<<toH<<endl;
}
return 0;
}