fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve()
  5. {
  6. double a, d, c, p, n;
  7. cin >> a >> d >> c >> p >> n;
  8. //ct^2 + (2d + c)t - 2(n-a) = 0
  9. double D = (2.0*d + c) * (2.0*d + c) + 8.0 * (n-a) * c;
  10. double T = sqrt(D) - (2.0*d + c);
  11. T /= (2.0*c);
  12. cout << max(0, (int)(ceil(T) * p)) << endl;
  13. }
  14.  
  15. int main()
  16. {
  17. int t;
  18. cin >> t;
  19. while (t--)
  20. solve();
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3276KB
stdin
4
1 3 2 5 20
4 1 7 3 30
3 6 2 4 25
8 4 1 6 34
stdout
15
9
12
24