×

# Effect of int , long int or long long int on time

 1 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? asked 20 Mar '17, 13:59 52●4 accept rate: 16%

 1 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 answered 20 Mar '17, 14:27 15.4k●1●20●66 accept rate: 18% That sound's more convincing that how using long long int instead of long int can cause tle. Thanks! (20 Mar '17, 19:47)
 1 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 ! . answered 20 Mar '17, 14:32 1.2k●10 accept rate: 15% That's a very elegant, practical example. (20 Mar '17, 14:34) 1 Thank for help @pankajkhan :) (20 Mar '17, 19:46)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×720
×204
×7

question asked: 20 Mar '17, 13:59

question was seen: 291 times

last updated: 20 Mar '17, 19:47