Please someone tell why I am getting WA, then a TLE for task 2, but AC for task 1 in GCDQ

Here is the link to code:(

1 Like

See the complexity of your code. For every query, it’s taking 2N iterations + N more for the gcd function. The total iterations are then thus (No_of_queries)(2N+N). For the second subtask, accoridng to the maximum number of queries and the value of N, these operations can’t be executed in the given time limit. Thus, you are getting TLE. Hence, you need to optimize your logic.

Happy coding… :slight_smile:

Ok, but why is it giving WA for task 5 & 6, as shown below

Correct Answer
Execution Time: 0.00

Sub-Task Task # Score Result
1 1 NA AC
1 2 NA AC
1 3 NA AC
1 4 NA AC
Final Score - 40.000000 Result - AC

2 5 NA WA
2 6 NA WA
2 7 NA TLE
2 8 NA TLE
2 9 NA TLE
Final Score - 0.000000 Result - WA

See this test case:
5 3
100000 1000 10000 100000 3254
1 3
2 5
3 4

There is something wrong in your code due to which it gives output as

You are printing some extra values somewhere I suppose. The correct output is:

For running one, you may see: I know test cases are minimum 2, but that doesnot matter. You can add any other test case and then check. It’ll give the same wrong answer that way also.

Sometimes there is an issue of the datatype we are using in our code, like they are asking for a long long integer type but we are using only integer type. So our code is not able to satisfy the constraints. Therefore, checking for the constraints and datatypes is very small thing, but should be taken into consideration for getting correct answer.