Out of curiosity, I want to ask what difference does it make to use int , long int or long long int on the time taken by the code to execute successfully.

I already know that it can cause Wrong Answer but how does it affect on time?

This question has been asked several times. I will include the relevant links soon (give me ~10-15 min). EDIT- Here is the link Why long long int causes TLE

The basic concept is that, a long long int will take two operations instead of 1 on it.

Visualisation- A 32 bit system, which has 32-bit cells to store stuff, would store 64-bit long long int by “splitting” it into two 32 bit ones and storing each in a cell and working on both of them. So number of operations double.

Basic idea is that long long int take twice the operation than int. Eg, if (int) 5+3 is 1 operation, but (long long int ) 5+3 is 2 operation

Check it for yourself. Run these codes on the Code, Compile and Run and check the time taken below:

int i,j;

for(i=0;i<1e+9;i++)

j=sqrt(i);

long long i,j;

for(i=0;i<1e+9;i++)

j=sqrt(i);

I hope you will understand the difference ! .

That’s a very elegant, practical example.

That sound’s more convincing that how using long long int instead of long int can cause tle. Thanks!