PROBLEM LINK:Author: Kaushik Iska DIFFICULTY:Simple PREREQUISITES:Programming Language PROBLEM:Define F[1] = S, F[i > 0] = F[i  1] * (C + 1). Determine whether F[D] >= L. EXPLANATION:First of all ,we need to observe that F[] is monotone increasing, because of (C + 1) > 1. Second, F[] is increasing exponentially, while L is smaller than 10^9. That means, only O(log L) days are needed for F[D] to exceed L. Third, when F[] exceed L, it is possible about 10^18 (exceeding int in C++ and Java). So please choose the appropriate type to store. In summary, what we need to do is calculate F[0..D] one by one, until all D + 1 ones are got or some one is greater than L. The time complexity is in O(min{D, log L}). AUTHOR'S AND TESTER'S SOLUTIONS:Author's solution can be found here.
This question is marked "community wiki".
asked 13 Jan '14, 15:12

During the contest, I simply derived the general formula in terms of day 1, and, afterwards, some simple maths and logarithm application allowed me to test for the problem's codition simply like this:
I guess this a lot less complicated than being mislead or caught in overflow errors :) Best, Bruno answered 13 Jan '14, 16:40

This one is also simpler . include<stdio.h>include<math.h>main() { double T,i,D,C,S,L;
} answered 13 Jan '14, 18:39

THIS ONE DERIVES GENERAL FORMULA AND COMPARES THE VALUE IN LOG SPACE INSTEAD,ITS A FAR SIMPLER METHOD import sys from math import log def solve(value): if value[2] >= value[0]: print "ALIVE AND KICKING" return
input = sys.stdin.readlines() N=int(input.pop(0)) for line in input: values = [] # values are L,D,S,C values = map(int,line.split()) solve(values) answered 14 Jan '14, 00:27

include <iostream>include <math.h>typedef long double lf; using namespace std; int main() { lf t,i,s,c,d,l,d1; cin>>t; while(t) { cin>>l>>d>>s>>c; s=s*pow(c+1,d1); if(s>=l) cout<<"ALIVE AND KICKING"<<endl; else cout<<"DEAD AND ROTTING"<<endl; } return 0; } answered 12 Nov '16, 14:06
but when i give long long int ,it shows wrong answer...please help!!!.
(12 Nov '16, 14:07)
@vivek7119 size of long double at codechef is 12 bytes and size of long long int is 8 bytes, may be that's why your program fails on taking long long int.
(12 Nov '16, 14:23)

Ideone Long long int also works in this case. answered 16 Jun '17, 11:59

This is giving a runtime error(NZEC). Any reasons? answered 26 Oct '17, 00:59
