About lld and I64d

Recently, on this problem, I got WA with I64d, and AC with lld (links to relevant submissions: with lld, and with I64d). On Codeforces custom invocation, and my computer, %lld, and %I64d both work fine. In fact, most people recommend using %I64d, as %lld is slightly unsafe to use (because of typecasting issues). Now, my question is: why does this happen? (I’m sorry if this is obvious, but I searched this up, and couldn’t find anything)

This is an interesting topic. Let’s break down what I64d means to begin with.

I64d is not the best way to handle long long types. This is a Microsoft way to support coders when processors were 32 bits length.

“I 64 d” stands for “integer of 64 bits”.

That was useful in that context, but when are you going to find a 32 bits processor in a contest nowadays? Plus, implying that the server is Microsoft related somehow (more than 95% servers worldwide are Linux distros).

Now, Linux and Microsoft users had a bad time in the 80-90’s, and even in the 2000’s. Compilers, Operating Systems, even peripherals were a war matter. So, the fact that “I64d” worked in Linux was only on those projects that were Microsoft related or Linux projects that wanted to be Microsoft friendly.

Those times are over. Linux programmers are stronger than Microsoft. For what matters here is that the most likely thing is that the compiler that CodeChef server is using is Linux related. You don’t see it, but veeeery probably the compiler throws a warning saying “I don’t care your Microsoft coding, I’m Linux”.

I’m joking. It would probably say something like “Warning: integer format is wrote, but long long type is received”.


Your I64d is being ignored by the server’s compiler. You saying integer? Then integer. So 32 bits length. That’s its logic. So your long long type is being truncated.

This is fun to know, but don’t lose your head over this. Use GNU canonical ways (lld).

It’s funny to know how even something as mathsly as programming is has a background drama. Computers are made by humans after all.

Proof on how the compilation is made, (so no Compilation Error), but it does not guarantee the behavior is what you expect.

Typo. Integers are 16 bits.

I see. Since Codeforces and my computer are both Microsoft environments, this works here, and not in CodeChef which is a Linux environment. Thank you for the response! Darn C is hard. Maybe I should just stick to C++.

1 Like