Codeforces Round #125 (Div. 1) A. About bacteria

Source: Internet
Author: User

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

At the beginning of the first experiment there are a single bacterium in the test tube. Every second each bacterium in the test tube divides itself intok bacteria. After that some abnormal effects createB to bacteria in the test tube. Thus, if at the beginning of some second the test tube hadx bacteria and then at the end of the second it would have< c6>kx? +? b bacteria.

The experiment showed that after n seconds there were exactlyZ bacteria and the experiment ended at this Point.

For the second experiment Qwerty are going to sterilize the test tube and put theret bacteria. He hasn ' t started the experiment yet but he already wonders, how many seconds he'll need to grow at leastz bact Eria. The ranger thinks that the bacteria would 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 leastZ bacteria in the second exp Eriment.

Input

The first line contains four space-separated integers k,b, n andT (1?≤? K,? b,? n,? t? ≤?106) -the parameters of bacterial growth, the time Qwerty needed to growz bacte Ria 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 leastz bacteria in the tube.

Sample Test (s) Input
3 1 3 5
Output
2
Input
1 4 4 7
Output
3
Input
2 2 4 100
Output
0 The main idea: culture bacteria, 1 bacteria per second to increase the number of k*x+b, to find t bacteria after how many seconds to grow to Z. N is 1 bacteria increased by n seconds to Z,t is the second group just beginning to have t bacteria due to the--int64 range of 9*10^19 around, but this problem if directly do t* (K*X+B), very likely super __int64
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <cmath > #include <algorithm> #define LL  __int64#define inf 0x3f3f3f3fusing namespace std; ll P[1000000];int Main () {    ll n,m,i,j,k;    LL b,t;    while (~scanf ("%i64d%i64d%i64d%i64d", &k,&b,&n,&t))    {        LL tmp=0;        LL x=1;        while (tmp<=n&&t>=x)        {            x=k*x+b;            tmp++;        }        printf ("%i64d\n", n-tmp+1);//use N (1 bacteria to increase the time spent in T) =t time to increase to Z <span id= "Transmark" ></span>    }    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round #125 (Div. 1) A. About bacteria

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.