Marking borders

Can anyone please tell me the problem in this code?
https://www.codechef.com/CROS2020/submit/COCR104

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int t;
cin>>t;
while(t–)
{
long long int a,b,l,r;
cin>>a>>b>>l>>r;
int c=0;
int s = 0;
if(a>=l && a<=r)
{
c++;
s=a;

   int i=1;
    
   while(1)
   {
       if(i%2 !=0)
       {
           s= s+b;
           {
               if(s<=r)
               c++;
               
               else
               break;
           }
       }
          if(i%2 ==0)
       {
           s= s+a;
           {
               if(s<=r)
               c++;
               
               else
               break;
           }
       }
       i++;
   }
    }
   cout<<c<<endl;
}

return 0;

}

this code will give TLE as it is using a brute force approach for example l==1,r==10^9,x==1,y==1,it will fail

But it is successfully executing in the case you said.

yes it is because u r running on T==1 but even if T==6 is there and we copy same case 6 times it will give TLE and we have 10^5 test cases and hence this code will surely fail.I request to refer any code from editorial.