rt,不小心算出了近似圆周率。
#include <iostream>
#include <cmath>
using namespace std;
long long count_squares_in_circle(int R) {
long long count = 0;
long long R2 = (long long)R * R;
for (int i = -R; i <= R; ++i) {
if ((i + 0.5) * (i + 0.5) > R2) {
continue;
}
int max_j = floor(sqrt(R2 - (i + 0.5) * (i + 0.5)));
int min_j = ceil(-sqrt(R2 - (i + 0.5) * (i + 0.5)));
if (max_j >= min_j) {
count += (max_j - min_j + 1);
}
}
return count;
}
int main() {
int R;
cin >> R;
cout << count_squares_in_circle(R) << endl;
return 0;
}