We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Extremely Dangerous Virus
Extremely Dangerous Virus
Sort by
recency
|
9 Discussions
|
Please Login in order to post a comment
Python 3 solution for cases where a+b is even (all test cases):
static int solve(int a, int b, long t) {
`
GIven probability is 0.5 ( 1/2 ) . Factors are a and b . Initially cell is 1
Every time ,it grows according expected value using factor given a & b
fIrst time virus cell will be (a*(1/2)) + (b*(1/2)) = (a+b)/2;
Now cells are (a+b)/2; Now this will be growing into again by factor a & b with probability (1/2) .Let's see ....................
a*( ( a + b ) / 2 ) * ( 1 / 2 ) + b* ( ( a + b ) / 2 ) * ( 1 / 2 )
= ( ( a + b ) / 2 ) * (( a + b ) / 2 ) ) , when time is 2 milisecond .
So from this pattern , we can say ( ( a + b ) / 2 ) ^ t ....... %mod .
` My code
Initially there is a single virus who replicates into (a+b)/2 expected number of viruses at time=1 ms. These (a+b)/2 new viruses further replicate into (a+b)/2 new viruses each at time=2 ms.
Let us call (a+b)/2 as mean.
Total number of viruses at time=2ms:
=mean*mean
=mean^2
After time=t ms, mean^t;
A simple pow(mean,t) should work if value of t is small. However, in this case, we need to use fast exponentiation.
There seems to be something funny going on with the math here.
According to my "correct" answer; If there is a 50% probability that the number of cells doubles every millisecond, and you carry out the experiment for 1,000,000 milliseconds, the expected number of cells is still 1.
Surely this can't be correct?
(My answer is pretty much the same as Kunal07's)