winner codes : unable to understand the expression

In the last Long Contest FEB15 there was a solution submitted by rns4
for the problem Let us play with rank list -> RANKLIST
and his solution is here ->

inside it there is two expression at different lines

ll x= 1ll*n*(n+1)/2;

x= 1ll*(n-j)* (n-j+1)/2+ j;

i want to know that what is the use of 1ll or why it has been used here.

1 Like

n is of type int , and n*(n+1)/2 may overflow the range of int, so 1ll is multiplied with n, so that the result is of long long type (ll stands for long long).


Read This link. It discuses the same question.

1 Like

can we use type casting instead of multipling 1ll, i guess it will work same.

Yes you can use typecasting. But, you should be careful to typecast at the proper place. If you only typecast the result of the expression, then, it will be too late get back your lost digits.

1 Like