Advertisement
Rofyda_Elghadban1

Untitled

Aug 29th, 2023
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. int t;
  2.  cin>>t;
  3.  while(t--){
  4.   ll l,r,a,counter1=0,ans1=0,counter2=0,ans2=0,res=0,maxi=INT_MIN;
  5.   cin>>l>>r>>a;
  6.   for(ll i=l;i<=r;i++){
  7.     if(counter1==0){
  8.       if(i%a==0){
  9.         ans1=i;
  10.         counter1++;
  11.         break;
  12.       }else{
  13.         continue;
  14.       }
  15.     }else if(counter1==1&&counter2==0){
  16.       if(i%a==0){
  17.         ans2=i;
  18.         counter2++;
  19.         break;
  20.       }else{
  21.         continue;
  22.       }
  23.     }else{
  24.       continue;
  25.     }
  26.   }
  27.   if(counter1==1||counter2==1){
  28.     for(int i=ans1;i<=ans2;i++){
  29.       res=(floor(i/a))+(i%a);
  30.       maxi=max(res,maxi);
  31.     }
  32.   }cout<<maxi<<"\n";
  33.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement