P14027 题解
题目传送门
题意简述
给定三个整数
算法一
注意到
while(a<b)
ans++,a=max(a+k,a*k);
时间复杂度
算法二
重头戏来了
我们可以感觉到
·
这时
·
第一次操作时,
对于正常情况,每次都执行
求
double logbase(double x,double y){//求log_x y
return log(x)/log(y);
}
时间复杂度
完整代码
#include<bits/stdc++.h>
using namespace std;
double a,b,k;
double logbase(double x,double y){
return log(x)/log(y);
}
int main(){
cin>>a>>b>>k;
if(k==1)//k=1直接输出
cout<<b-a;
else if(a<=1)//a=1,a+=k后按正常处理,不要忘了加1
a+=k,cout<<ceil(logbase(b/a,k))+1;
else
cout<<ceil(logbase(b/a,k));
return 0;
}