Extremely Dangerous Virus

  • + 0 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.

    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;
    }