getting right output but codeChef showing wrong answer.

#include <stdio.h> #include <math.h> int main(void){ int t, a=0, b=0, n=0, r; scanf("%d",&t); while(t--){ scanf("%d %d %d",&a,&b,&n); a=pow(a,n); b=pow(b,n); if(a>b) r=1; else if(a<b) r=2; else if(a==b) r=0; printf("%d",r); } }

having same problem

The problem with using pow function is that max value it can return is 10^18. According to the constrains a and b are <10^9 and c<10^9 , so this is leading to overflow. I think you have to come up with better solution…

Hint :- Try not comparing pow(a,c) and pow(b,c) instead compare a and b…

The constraints given in the question are:
For larger numbers in the range such as taking the example of a=1000, b=100, n=1000, when you calculate pow(a,n) and pow(b,n), the answer is inf, i.e., infinity for both. Thus, the compiler treats both pow(a,n) and pow(b,n) to be the same because you can’t differentiate one infinity from another. So, the answer for your code is 0 for large numbers as such even when a^n is not equal to b^n.
With some proper insight into the conditions, you can solve the problem without calculating pow(a,n) and pow(b,n). Here is my solution: You can also view the editorial here: NUMCOMP - Editorial