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:(http://ideone.com/M8nh3U)

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
(time)
1 1 NA AC
(0.000000)
1 2 NA AC
(0.000000)
1 3 NA AC
(0.000000)
1 4 NA AC
(0.000000)
Final Score - 40.000000 Result - AC

2 5 NA WA
(0.110000)
2 6 NA WA
(0.160000)
2 7 NA TLE
(3.010000)
2 8 NA TLE
(3.010000)
2 9 NA TLE
(3.010000)
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
2
100000
2
0
100000

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

For running one, you may see: http://ideone.com/rFFc7l 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.