[Guidance] What's the method to get precision till decimal place defined by user ?

I am working on this problem LMA1

I tried this method from the editorial. Why am I getting WA ?

#include<bits/stdc++.h>
using namespace std;

int main(){
ios::sync_with_stdio(0);
double t,a,n,p,d,q;
cin>>t;
while(t--){
	cin>>a>>p>>q>>d;
	cout<<setprecision(d)<<(p*a*(1-a)+(q*a))/((1-a)*(1-a))<<endl;
	
}

return 0;
}

You can’t solve it in this way; precision of standard C++ data types is far from 10000 digits :slight_smile:

Check editorial (and codes provided there) once again to get the idea how to calcualte digits of common fraction one by one.

Can you tell me why my code is not accepted please ? :slight_smile:

Kinda obvious answer - because it gives wrong answer.

I already said it in my message above.

1 Like

try writing cout<<fixed<<setprecision(d)<<… instead of only cout<<setprecesion(d)<<…

try writing cout<<fixed<<setprecision(d)<<…instead of cout<<setprecision(d)<<…