fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. ios_base::sync_with_stdio(0); cin.tie(0);
  6. // freopen("input.txt", "r", stdin);
  7. // freopen("output.txt", "w", stdout);
  8. double a,b,r;
  9. cin >>a >>b>>r;
  10. long long cnt=0;
  11.  
  12. // cout << (a*a + y*y -2*a*y + b*b -r*r) << endl;
  13. // cout << ceil(b-r) << ' ' << floor(r+b) << endl;
  14. for (int y = ceil(b-r);y<=floor(r+b);y++){
  15. double dy = (double)y;
  16. // cout << dy << " " << a << " " << b << endl;
  17. // cout << a << ' '<< dy << ' ' << b << endl;
  18. double denta = 4.0*a*a -4*( a*a+dy*dy - 2*a*dy + b*b - r*r);
  19.  
  20. // cout << denta << endl;
  21. // cout << (double)sqrt(denta) << endl;
  22. double x1 = (2*a - sqrt(denta))/2;
  23. double x2 = (2*a + sqrt(denta))/2;
  24. int k1=ceil(x1);
  25. int k2=floor(x2);
  26. // cout << y << ' '<< x1 << ' ' << x2 << endl;
  27. // cout << y << ' '<< k1 << ' ' << k2 << endl;
  28. cnt = cnt + abs(k2-k1) +1;
  29. }
  30. cout<<cnt;
  31. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
2