Advertisement
Saleh127

Light OJ 1275

Sep 15th, 2021
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5.  
  6. ll factor(ll n,ll c,ll t)
  7. {
  8. return t*(c-t*n);
  9. }
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0);cout.tie(0);
  15.  
  16. test
  17. {
  18. ll n,c,x1,x2,x3,a1,a2,a3;
  19.  
  20.  
  21. cin>>n>>c;
  22.  
  23. cout<<"Case "<<cs<<": ";
  24.  
  25. if(n==0)
  26. {
  27. cout<<0<<endl;
  28. continue;
  29. }
  30.  
  31. //x=-(b/2a) as b=1 and c =0 for ax^2 + bx + c;
  32.  
  33. x1= c/(2*n);
  34. x2= 1 + c/(2*n);
  35. x3= c/(2*n) - 1;
  36.  
  37. //as we want int max value that's why x-1,x,x+1;
  38.  
  39. a1=factor(n,c,x1);
  40. a2=factor(n,c,x2);
  41. a3=factor(n,c,x3);
  42.  
  43. if(max(a1,max(a2,a3))==a1) cout<<x1<<endl;
  44. else if(max(a1,max(a2,a3))==a2) cout<<x2<<endl;
  45. else if(max(a1,max(a2,a3))==a3) cout<<x3<<endl;
  46.  
  47. }
  48.  
  49.  
  50. return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement