### ie_fauxpas's blog

By ie_fauxpas20 months ago, ,

I've spent two days now on this problem — it should be easy but I keep getting test 16 incorrect and I don't know why!

My code is pretty simple and straightforward:

``````int main(int argv, char* argc[]) {

double m, n, a;
while (scanf("%lf %lf %lf", &n, &m, &a) != EOF) {

// Initiaslise tiles counters as 1 because we will
// always have at least 1 tile.
long long horiz = 1;
long long vert  = 1;

while (a < n) {

n -= a;
horiz ++;
}

while (a < m) {

m -= a;
vert ++;
}

printf("%d\n", (horiz * vert));
}

return EXIT_SUCCESS;
}

``````

Yet test 16 (m=1000000000, n=1000000000, n=192) returns a negative number! I get the following:

wrong answer 1st numbers differ — expected: '27126743055556', found: '-270385980'

Arrrgh why??

 » 20 months ago, # |   +1 You should output long long numbers with %lld, not %d.
•
 » » 20 months ago, # ^ |   0 Though there are some troubles with compilers here, so input/output for long long numbers with specifier "%lld" is not recommended/supported. Also, I'm not sure that your algo is correct.
•
 » » » 20 months ago, # ^ |   0 Yeah, I tried %llu first and then it told me to use %I64d, which I guess refers to a 64 bit number?
•
 » » 20 months ago, # ^ |   0 Thankyou! That was driving me crazy! It's too slow though, I need to work out a faster way to solve it.

 » 20 months ago, # |   0 I don'know why are you using double, just use ll or llu(read with %I64d or with cin) and i think its so sloow algorithm :)
•
 » » 20 months ago, # ^ |   0 Yes, it's too slow to pass all the tests! I couldn't think of any other way to solve it though, I am only a first year comp sci student!