UVa 10056 - What is the Probability ? Solution

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--){
        int n,i;
        double p,q;
        cin>>n>>p>>i;
        q=1-p;
        if(p>0)
            cout<<fixed<<setprecision(4)<<(p*pow(q,i-1))/(1-pow(q,n))<<endl;
        else
            cout<<"0.0000"<<endl;
    }
}

Comments