//Hello. I‘m Peter.
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define MAXN
#define N
#define M 35
ll k,b,n,t,m;
const double eps=1e-9;
int dcmp(double x){
if(fabs(x)<eps) return 0;
else if(x<0) return -1;
else return 1;
}
int main(){
cin>>k>>b>>n>>t;
if(k==1){
ll t1=n*b+1;
t1-=t;
if(t1<=0) cout<<0<<endl;
else{
ll ans=t1/b;
if(ans*b!=t1) ans++;
cout<<ans<<endl;
}
exit(0);
}
double y;
y=log(k-1+b)+n*log(k)-log(t*(k-1)+b);
if(y<0) m=0;
else{
m=y/log(k);
if(dcmp(m*log(k)-y)<0) m++;
}
cout<<m<<endl;
return 0;
}
Codeforces Round #125 (Div. 1 A)
原文地址:http://blog.csdn.net/uestc_peterpan/article/details/45564869