Ishtiaque and the Rabbit

Limits 1s, 512 MB

Mr Ishtiaque is in trouble. A few months ago, he bought 2 rabbits. He wanted to have two pet rabbits. But he did not know that rabbits reproduce so fast. Now, his little balcony has been filled up with rabbits. So he decided to build a big house for his pets. But he needs an estimation about how many rabbits will be there by the end of the year. As he is a teacher and moreover he has to take care of his rabbits everyday, he do not have much time to make the estimation. So he needs your help regarding this issue. He will provide some information about the rabbits.


This is a companion discussion topic for the original entry at https://toph.co/p/ishtiaque-and-the-rabbit

I think the CPU limit should be increased for python.

Datasets are weak I think. O(n*t) solutions are passing. According to the constraints it shouldn’t happen. Thank you. <3

You want better algorithms than O(n) ?
I donot think that the fact that linear solutions are accepted should cause any problem though.

I wanted to say that, the main solve is O(n) and as there are test cases, So the full solve becomes O(n*t). For the worst case, can it work in 1 second?

@hjr265 if you have time can you see that once?

Increase the time limit for python.
Here is my code: [It’s getting cle in last case]

num_test = int(input())
for i in range(num_test):
    a, b, c = map(int, input().split())
    num_rabbit = a
    for j in range(1, c):
        num_rabbit += a * b**j
    print(num_rabbit)

the tags of this problem may help I think!:smiley:

why it gives me “wrong answer”
i think my answer is correct

#include <stdio.h>
#include<math.h>

int main() {
    long long a, b, c, d, e, f, g;
    scanf("%lld", &a);
    for(b=0; b<a; b++){
        g=0;
        scanf("%lld %lld %lld", &c, &d, &e);
        g=(pow(d,e)-1)*c/(d-1);
        printf("%lld\n", g);
    }
	return 0;
}