Consigne: each integer is in the inclusive range 1 - 109.
I use variable with the type unsigned long long int
Is it enough for the stated range?
Consigne: each integer is in the inclusive range 1 - 109.
I use variable with the type unsigned long long int
Is it enough for the stated range?
Yes it is (assuming that you are adopting the notation 10^9
to mean 1e9
- ^
is the XOR operator in C, and 10^9
is 3
).
An unsigned long long
has to be capable of storing a number between 0 and 264 - 1. Your maximum is much smaller than this.
Note also that an unsigned long
has to be capable of storing a number between 0 and 232 - 1. Your maximum is also smaller than this.
10^9 is way smaller than 2^32
So in your case, no need to use unsigned long long
(it fits, yes), which is overkill and can lead to slower operation.
Use the proper type, normalized in stdint.h
include: uint32_t
or uint_least32_t
(uint32_t vs uint_fast32_t vs uint_least32_t)
long
is also guaranteed to be at least 32 bits, so it's a good & simple choice as well.
Long long unsigned integer type. Contains at least the [0, +18,446,744,073,709,551,615] range; Specified since the C99 version of the standard.
The answer is yes, but you don't need unsigned long long
, unsigned long
would be enough.
A 32 bit number can represent over 4 * 10^9. Up to 4 294 967 296.