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

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 k,
b, n 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个细菌每秒增张为k*x+b,求t个细菌经过多少秒后增长到Z个。n是1个细菌经过n秒增加到Z,t是第二组刚开始有t个细菌
由于——int64的范围为9*10^19左右,但是此题如果直接做t*(k*x+b),很有可能超__int64
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL  __int64
#define inf 0x3f3f3f3f
using 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);//用n-(1个细菌增加到t个所用的时间)=t增加到Z所用的时间<span id="transmark"></span>
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-14 10:20:51

Codeforces Round #125 (Div. 1) A. About Bacteria的相关文章

Codeforces Round #125 (Div. 1 A)

http://codeforces.ru/contest/198/problem/A Problem 一个数x,起初x=1,然后,每次进行x=x*k+b操作,进行n次,得到一个数z.现在,给一个数y,起初y=t,然后进行y=y*k+b操作,问至少进行多少次使得z≤y. 数据范围 1≤k,b,n,t≤106,单case Solution 会发现z=kn+bkn?1+...+bk+b,假设进行了m次,m≤n,y=tkm+bkm?1+....+bk+b,发现,z和y都含有bkm?1+...+bk+b,

Codeforces Round #259 (Div. 2) 解题报告

终于重上DIV1了.... A:在正方形中输出一个菱形 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月01日 星期五 23时27分55秒 4 5 #include<vector> 6 #include<set> 7 #include<deque> 8 #include<stack> 9 #include<bitset> 10 #inclu

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #424 (Div. 2) E. Cards Sorting(线段树)

题目链接:Codeforces Round #424 (Div. 2) E. Cards Sorting 题意: 将n个数放进一个队列,每次检查队首,看看是不是队列中最小的数,如果是就扔掉,如果不是就放到队尾. 这样直到队列为空,为需要操作多少次. 题解: 考虑用两个指针模拟,最开始now指针指向第一个数,然后nxt指针指向下一个将要被删除的数. 然后我们要算出这里需要移动多少步,然后删掉这个数,一直重复操作,直到将全部的数删完. nxt指针可以用set来维护,now指针可以用并查集来维护. 计

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo

二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

题目传送门 1 /* 2 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 using namespace std; 8 9 const int MAXN = 5e2 + 10; 10 const int MAXM = 1e6 + 10; 11 const int INF = 0

CodeCraft-19 and Codeforces Round #537 (Div. 2) - D. Destroy the Colony(动态规划+组合数学)

Problem  CodeCraft-19 and Codeforces Round #537 (Div. 2) - D. Destroy the Colony Time Limit: 2000 mSec Problem Description Input Output For each question output the number of arrangements possible modulo 10^9+7. Sample Input abba21 41 2 Sample Output

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i