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 1209. 1, 10, 100, 1000...

Why??? WA on test 1
Posted by adminsever 23 Jan 2012 20:44
test ID: 4088875

Edited by author 23.01.2012 20:49
Re: Why??? WA on test 1
Posted by morbidel 23 Jan 2012 23:34
Post your source code.
Re: Why??? WA on test 1
Posted by adminsever 24 Jan 2012 14:09
#include <iostream>
#include <Cmath>

void main()
{
    int n, i;
    long nArray;
    static int q[65535];
    scanf("%d", &n);
        for(i = 0; i < n; i++)
        {
            scanf("%l", &nArray);
            if (floor((sqrtf(1 + 8 * (nArray - 1)) - 1) / 2) == ((sqrtf(1 + 8 * (nArray - 1)) - 1) / 2))
                q[i] = 1;
            else
                q[i] = 0;
        }
        for (i = 0; i < n; i++)
        {
            printf("%d ", q[i]);
        }
}
Re: Why??? WA on test 1
Posted by morbidel 24 Jan 2012 16:57
Hi,

Some observations:
 - you read a long with %l instead of %ld, which gives then WA3. The %l is not a valid scanf format specifier. On GCC the function doesn't even work (no value read) and on VS2010 the function works but returns junk.
 - the multiplication 8 * (nArray - 1) overflows the float type as also the long type (nArray can be at most 2^31 - 1). You should convert the multiplication to something bigger, for example the double type. Change also the sqrtf to sqrt.

You'll get AC
Re: Why??? WA on test 1
Posted by adminsever 25 Jan 2012 19:20
Thank you!
I used type Double and %lf to the read. And get AC.

P.S. Sorry for my bad English :(