【CodeForces - 199C 】【About Bacteria】

版权声明:本人原创,未经许可,不得转载 https://blog.csdn.net/qq_42505741/article/details/83314732

题目:
 

Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.

At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into k bacteria. After that some abnormal effects create b more bacteria in the test tube. Thus, if at the beginning of some second the test tube had x bacteria, then at the end of the second it will have kx + b bacteria.

The experiment showed that after n seconds there were exactly z bacteria and the experiment ended at this point.

For the second experiment Qwerty is going to sterilize the test tube and put there tbacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least z bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment.

Help Qwerty and find the minimum number of seconds needed to get a tube with at least z bacteria in the second experiment.

Input

The first line contains four space-separated integers kbn and t (1 ≤ k, b, n, t ≤ 106) — the parameters of bacterial growth, the time Qwerty needed to grow zbacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.

Output

Print a single number — the minimum number of seconds Qwerty needs to grow at least z bacteria in the tube.

Examples

Input

3 1 3 5

Output

2

Input

1 4 4 7

Output

3

Input

2 2 4 100

Output

0

解题报告:这道题是真的真的坑,读不懂,一上来满脸懵逼,根本不知道输入输出都是代表的啥。自己懵逼了很久之后(看了n次题目)总算是有点是理解了。输入k b n t。 k代表是增长频率  b代表是最初数目  t代表是希望达到的数目  n是限制的时间长。

这样就可以写出循环来,让sum不断的增加,然后达到条件的时候跳出,再进行判断跳出的时间i 和限制的时间 n比较,从而输出正确结果。

ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;

int main()
{
	ll k,b,n,t;
	while(cin>>k>>b>>n>>t)
	{
		ll sum=1;
		int i=0;
		for(i=0;sum<=t;i++)
			sum=sum*k+b;	
		if(i>n)
			printf("0\n");
		else
			printf("%lld\n",n-i+1);
	}	
	
} 

出题人很强,硬是将比较简单的问题搞成了看不懂系列。。。

猜你喜欢

转载自blog.csdn.net/qq_42505741/article/details/83314732