ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Wrong answer (C)
Posted by alexanius 6 Sep 2017 04:44
The tests from example and few other are ok, but it gets wrong answer in test1.

#include <math.h>
#include <stdio.h>

#define SIZE (256 * 1024) / sizeof(long long)
long long int n[SIZE + 1];

int main(void)
{
        int s = 0, l;
        do{ l = scanf("%lld", &(n[s])); s++; } while(l != EOF);
        s -= 2;

        for(;s >= 0; s--) printf("%.4Lf\n", sqrtl(n[s]));
        return 0;
}
Re: Wrong answer (C)
Posted by alexanius 16 Sep 2017 19:57
The problem here is that system accepts

printf("%.4f\n", sqrt(n[s]));

but does not accept

printf("%.4Lf\n", sqrtl(n[s]));

It is a bit strange because the second version is more precise. It would be great if some one showed a false test for the second variant.
Re: Wrong answer (C)
Posted by Mahilewets Nikita [BSUIR] 16 Sep 2017 20:09
Maybe you were printing something like 1.23456e-789?
To admins Re: Wrong answer (C)
Posted by alexanius 17 Sep 2017 04:33
No, L is a modifier for extended data type. To be sure I tried the following variant:

printf("%.4Lf\n", sqrt((double)n[s]));

and it passed. So the only problem is difference between sqrt and sqrtl.

To admins: I think that at least one of the tests gives different values when using sqrt and sqrtl. And more precise variant fails. Please check my guess, I think that using of both functions should be valid.