Same Program but Different result

I was just practicing Question in Codechef and I came through this Question:
Question: PRIME1
I was trying my algo to submit this problem but every time I was getting TLE. I thought there must be a better algo than this. So, I went for the solution and this is the result I got.

My Solution: CodeChef: Practical coding for everyone
Random Solution: CodeChef: Practical coding for everyone

My Solution got TLE and in later case it got accepted. Please review it.

Computations on long long require more time than on plain int.

2 Likes

Are you sure this may be the reason because I used long long datatype for computation of large values. Actually this algorithm is for computation of large values so how can a datatype may affect the time complexity. Integer has certain range, beyond this it cannot compute.

The solution that got accepted uses int data type, so int is sufficient. So, in spite of the range issue, the accepted solution can calculate the required solution.
Remember that, the long data type uses 8 bytes of storage, but the int data type uses only half of that. If you disassemble your program, you’ll find different sets of instructions for the two. Now your job is to compare the time taken by each and come to the conclusion. :slightly_smiling_face:

It may require twice time to execute because long long int’s size is twice.

1 Like