Liste des Groupes | Revenir à cl c |
On Wed, 19 Mar 2025 17:38:12 +0000
Richard Heathfield <rjh@cpax.org.uk> wrote:
>On 19/03/2025 17:23, DFS wrote:>
>On 3/19/2025 5:55 AM, Michael S wrote:>
>On Wed, 19 Mar 2025 00:38:44 -0400>
DFS <nospam@dfs.com> wrote:
>On 3/18/2025 11:07 PM, Tim Rentsch wrote:>
>
>Have you thought about how large the value of 'n' can>
become inside the while() loop?
I was too smug in my first reply. After Keith pointed out I
needed
to read from stdin, I submitted the code again and it passed some
tests but failed with 'OUTPUT LIMIT EXCEEDED' when n = 159487.
>
Updating int to long worked, and now I'm bona fide!
>
So thanks.
What you did happens to be sufficient for a particular environment
(supposedly, x86-64 Linux) used both by yourself and by the
server that
tests results.
In more general case, 'long' is not guaranteed to handle
numbers in
range up to 18,997,161,173 that can happen in this test.
How did you determine that?
By the language definition.
Well, not exactly.
I never read C Standard docs except the very first one that I read
more that I read more than 33 years ago, so not very likely to
remember it literally.
Let's say that I know this particular bit of trivia from 1st hand
experience and from reading few ABI definitions.
>++++++++++++++++++++++++++++++++++++++++++++++>
>
5.2.4.2.1 Sizes of integer types <limits.h>
>
[...]
>
? minimum value for an object of type long int
LONG_MIN
-2147483647 // ?(231 ? 1)
>
? maximum value for an object of type long int
LONG_MAX
+2147483647 // 231 ? 1
>
++++++++++++++++++++++++++++++++++++++++++++++
>
That is, the long int type is required to have a sign bit and at
least 31 value bits, giving a guaranteed minimum range of
-2147483647 to 2147483647. That's 2 thou mill.
>
You can squeeze another bit out of it by going unsigned: 0 to
4294967295. That's 4 thou mill.
>
From C99 onwards you can use long long int to give you 63 (or 64
for unsigned) value bits - printf with %lld or %llu. Roughly 9
mill mill mill and 18 mill mill mill respectively.
I suspected that, but was not sure, so suggested to DFS a type that I am
sure about.
Les messages affichés proviennent d'usenet.