根据对称性求解出第一象限,然后乘以4加上四个坐标轴上的量即可得到最终的答案。根据几何图形的分析可以发现,假设从原点可以看见的树的坐标为(x,y),仅仅只有当gcd(x,y)==1的时候才不会被遮挡。所以问题也就变成了对于坐标x,首先求解小于等于x,并且和x互质的数的个数。同时我们可以发现,如果有gcd(x,y)==k那么肯定也就有gcd(x,y+x)==k,那么利用这条性质在纵坐标上就很好求解了,具体实现见如下代码:
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;
int a, b;
long long res;
long long amount;
long long getPhi(int t){
long long ans = t;
int temp = t;
int up = floor(sqrt(temp) + 0.5);
for (int i = 2; i <= up; i++){
if (temp%i == 0){
ans = ans/ i*(i-1);
while (temp%i == 0) temp = temp / i;
}
}
if (temp > 1) ans = ans / temp*(temp - 1);
return ans;
}
int gcd(int a, int b){
if (!b) return a;
return gcd(b, a%b);
}
long long cal(){
long long ans = 0;
for (int i = 1; i <= a; i++){
int k = b / i;
long long phi = getPhi(i);
ans += phi*k;
for (int j = k*i + 1; j <= b; j++) {
if (gcd(j, i)==1)
ans++;
}
}
return ans * 4 + 4;
}
int main(){
while (cin >> a >> b){
if (a == 0) break;
long long amount = cal();
long long total= (long long)(2 * a + 1)*(2 * b + 1) - 1;
cout << fixed << setprecision(7) << (double)amount / total << endl;
}
return 0;
}