Codeforces round #125 (Div. 2)/C. About Bacteria

Source: Internet
Author: User
C. About bacteriatime limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Qwerty the ranger took up a government job and arrived on planet Mars. he shoshould stay in the secret lab and conducting CT 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 itselfKBacteria.
After that some abnormal effects createBMore bacteria in the test tube. Thus, if at the beginning of some second the test tube hadXBacteria,
Then at the end of the second it will haveKxRegion + RegionBBacteria.

The experiment showed that afterNSeconds there were exactlyZBacteria
And the experiment ended at this point.

For the second experiment QWERTY is going to sterilize the test tube and put thereTBacteria. He hasn' t started the experiment yet but he already wonders,
How many seconds he will need to grow at leastZBacteria. 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 leastZBacteria in the second experiment.

Input

The first line contains four space-separated IntegersK,B,NAndT(1 digit ≤ DigitK, Bytes,B, Bytes,N, Bytes,TLimit ≤ limit 106 )-
The parameters of bacterial growth, the time QWERTY needed to growZBacteria 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 leastZBacteria 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
 
 
It was a very simple mathematical problem, and I didn't think of it at the time ......
It takes n seconds for one bacterial to multiply to Z by formula num = K * num + B. Then, if there are t in it, it will take several seconds to multiply to Z...
At the beginning, I thought I had to find out why Z didn't give it, but the number was too big to do...
But in fact, Z does not need to be calculated at all...
As long as a num is found to be no greater than T (more than t after reproduction), then the desired time (t is the time from t to Z) it must be the time from num propagation to Z ......
#include <iostream>using namespace std;int main(void){    long long k, b, n, t;    cin >> k >> b >> n >> t;    long long curr = 1, time = 0;    while (curr < t) {        curr = k * curr + b;        ++time;    }    if (curr > t) --time;    if (time > n) time = n;    cout << n - time<< endl;    return 0;}

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.