How can i keep my variable smaller than required constraint | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i keep my variable smaller than required constraint

i am practicing on codechef and according to constraint 1>N>2*10^5 how can i keep n smaller than 2*10^5, which data type i have to use.

30th Dec 2017, 2:15 PM
shobhit
shobhit - avatar
2 Answers
+ 5
@shobhit The constraint isn't interpreted like this. The constraint means that the input for this value (N in this case) will be between the provided range and so N must be of a proper type to be able to hold numbers in this range. It doesn't matter if the largest value for the type exceeds the range provided for the challenge code. So use long, 4 bit int or long long, as all of these can hold a number in the provided range without occurrence of overflow or underflow in the type.
30th Dec 2017, 4:51 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
why can't i store it in normal int and suppose if i store it in either of them according to constraint it must be smaller than 2*10^5. by storing it in int it can be bigger than that. plz correct me if i am wrong.
30th Dec 2017, 3:03 PM
shobhit
shobhit - avatar