Please read the new rule regarding the restriction on the use of AI tools. ×

vk705017's blog

By vk705017, history, 19 months ago, In English

can anyone tell why i am getting TLE in question this question 1804C - Вращайте барабан!
my code:197184238

  • Vote: I like it
  • -6
  • Vote: I do not like it

»
19 months ago, # |
  Vote: I like it +6 Vote: I do not like it

The loop for(int a=1;a<=p;a++) is doing p iterations in the worst case. As p can be up to $$$10^9$$$ and there can be up to $$$10^4$$$ testcases, the loop will do $$$10^{13}$$$ operations in the worst case. As a rough estimate, anything above $$$10^9$$$ will never fit in a time limit of 1 second. This will clearly TLE.

  • »
    »
    19 months ago, # ^ |
      Vote: I like it -6 Vote: I do not like it

    In case of recursion?

    • »
      »
      »
      19 months ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      I don't understand what you are trying to say. If you did this with recursion, it wouldn't be any faster without extra optimizations (which you could implement in the current approach as well).