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.
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.
long calc(int n, long long pow) //fast exponentiation
{
if(pow==0)
return 1;
if(pow==1)
return n;
long p=calc(n,pow/2);
p=(p*p)%mod;
if(pow%2!=0)
p=(p*n)%mod;
return p;
}
int main() {
long long t;
int a,b;
cin>>a>>b>>t;
int mean=(a+b)/2;
long p=calc(mean,t);
cout<<p;
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Extremely Dangerous Virus
You are viewing a single comment's thread. Return to all comments →
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.