I am very confused about when I should use double and when I should use long double.
In yesterdays educational round, my solution for 1009C - Надоевший подарок has failed for using double. After system testing, I resubmitted it using long double and it got accepted.
My solution using double got WA on test 39: 40379060
My same code replacing double with long double got accepted: 40379089
Update:
When I use long long tot
for storing the sum of all calculation and finally used double ans = tot*1.0/n
it also got accepted: 40379501 ! Why ?? Then why WA when using double tot
? Since the sum of all calculation don't have any precision or floating point value, precision is coming only when dividing by n, then why using double gave WA ?
As far as I know double can store value up to 1.8×10308 (approximately). So, why long double is needed here? Isn't double is enough here?
Also, during contest or online problem solving how should I decide which one I should use: double or long double?
Is it safe to use long double always for all problems? Or is there any specific case when I should use long double ?
Thanks in advance.