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

來源:互聯網
上載者: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 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 t bacteria. 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 z bacteria 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.

Sample test(s)input
3 1 3 5
output
2
input
1 4 4 7
output
3
input
2 2 4 100
output
0


很簡單的一道數學題,腦殘當時沒想出來。。。。。。
題目說1個細菌按公式num=k*num+b繁殖到z個需要n秒。然後問現在裡面有t個,則繁殖到z個需要幾秒。。。
剛開始在想z沒有給出還得求出來,但是數又很大沒法做。。。
但其實z根本不用算。。。
只要找到一個num剛好不大於t時(再繁殖一次就超過t了),則所求時間(t繁殖到z的時間)一定就是從num繁殖到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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.