fork download
  1. //H- n*(n+1)/2 * P + (n-1)*A <=0
  2. #include<bits/stdc++.h>
  3. #define LL long long int
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int t,cas=1;
  9.  
  10. scanf("%d",&t);
  11.  
  12. while(t--)
  13. {
  14. int h,p,a;
  15.  
  16. scanf("%d %d %d",&h,&p,&a);
  17.  
  18. LL lt=1,rt=1000000;
  19. LL ans=0;
  20.  
  21. while(lt<=rt)
  22. {
  23. LL mid=(lt+rt)/2;
  24. LL x=mid*(mid+1)/2;
  25. if(h- x * p + (mid-1)*a <=0)
  26. {
  27. ans=mid;
  28. lt=mid+1;
  29. }
  30. else
  31. rt=mid-1;
  32. }
  33.  
  34. printf("%lld\n",ans);
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 2688KB
stdin
3

3 7 2

81 4 1

87 8 4
stdout
1000000
1000000
1000000