4

I was submitting a matrix exponentiation code in C language for finding the nth fibonacci and I was using long long int variable for storing the answer modulo 10000007 of nth fibonacci, and the judge was giving "time limit exceeded" but when I used "unsigned long long int" my code was accepted within the time and the execution time was reduced.

I was unable to understand why long long int was giving "time limit exceeded" and "unsigned long long int" was accepted? (Answers for extreme test cases were coming correct in both cases)

L.ppt
  • 524
  • 6
  • 21

1 Answers1

5

In order not to replicate anybody's effort, please see this question and this more advanced question and answers of the same topic. dthorpe's answer in this one is highly detailed as well. wheaties' first comment here is worth checking as a first trial.

Community
  • 1
  • 1
OmarOthman
  • 1,718
  • 2
  • 19
  • 36
  • there is overhead when we use unsigned when mixed with doubles, but my code deals with the multiplication and "unsigned int" is working faster than the "int" and yes now i can also check for multiplication by comparing the assembly code for both kind of multiplications...:) – L.ppt Feb 18 '12 at 09:28