hi i am getting a tle for this problem
here is my code
[bbone=c,70]
include
include
int main()
{
//farey(2,2);
long long int n;
long long int a,b,c,A,B,d,k,sec;
long long int co;
long long int temp1,temp2,temp3,temp4;
long long int cou=1;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld",&n,&A,&B);
cou=1,sec=1;
a=0,b=1,c=1,d=n;
while(c<=n)
{
sec++;
k=(long long int)floor(((n+b)/d));
temp1=a;
temp2=b;
temp3=c;
temp4=d;
d=(k*temp4)-temp2;
c=(k*temp3)-temp1;
a=temp3;
b=temp4;
if(a==A && b==B)
{
// cout< printf("%lld\n",sec);
break;
}
}
}
return 0;
}
[/bbone]