fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef double DB;
  4. DB r1, r2, r, r12, r22;
  5.  
  6. /*{ self-adjasting simpson*/
  7. DB func(DB x) {
  8. x = x * x;
  9. return sqrt(r12 - x) * sqrt(r22 - x);
  10. }
  11. DB simpson(DB a, DB b) {
  12. return (func(a) + 4 * func(a + (b - a) / 2) + func(b)) * (b - a) / 6;
  13. }
  14. DB asr(DB a, DB b, DB eps, DB A) {
  15. DB c = a + (b - a) / 2;
  16. DB l = simpson(a, c), r = simpson(c, b);
  17. if(fabs(l + r - A) <= eps * 15) return l + r + (l + r - A) / 15.0;
  18. return asr(a, c, eps / 2, l) + asr(c, b, eps / 2, r);
  19. }
  20. DB asr(DB a, DB b, DB eps) {
  21. return asr(a, b, eps, simpson(a, b));
  22. }
  23. /*} end*/
  24.  
  25.  
  26. int main() {
  27. scanf("%lf%lf", &r1, &r2);
  28. r12 = r1 * r1, r22 = r2 * r2;
  29. r = min(r1, r2);
  30. printf("%.10lf\n", asr(0.00, r, 1e-8) * 8);
  31. return 0;
  32. }
  33.  
  34.  
Success #stdin #stdout 0s 3300KB
stdin
100 100
stdout
5333333.3333333330