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??
You should output long long numbers with %lld, not %d.
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.
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 :)
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!
It's just a little bit of math. Think of a way to how many times number can fit in another.
Seriously. After 3 years?
Of course. Knowledge for the future generations.
Wow! Thanks for the reply. I had completely forgotten about this challenge. I have almost finished my Comp. Sci. degree now, and you have inspired me to write a much more efficient algorithm to solve this problem :)