We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I know I have written stupid code and I am getting timeout for all test cases except 1. My program time compexity is o(n^2) as I have used 2 for loop. Can someone suggest better solution and try to explain why I am getting timeout error?
int i,j,r,k,t,count;
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
scanf("%d",&t);
while(t--){
scanf("%d%d",&r,&k);
count=0;
for(i=0;i<=sqrt(r);i++){
for(j=1;j<=sqrt(r);j++){
if(i*i+j*j==r)count++;
}
}
//printf("%d\n",count*4);
(count*4<=k)?printf("possible\n"):printf("impossible\n");
}
return 0;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Circle City
You are viewing a single comment's thread. Return to all comments →
I know I have written stupid code and I am getting timeout for all test cases except 1. My program time compexity is o(n^2) as I have used 2 for loop. Can someone suggest better solution and try to explain why I am getting timeout error?