UVA10214TreesInAWood

来源:互联网 发布:java hadoop 读取文件 编辑:程序博客网 时间:2024/06/15 05:27
//UVA10214TreesInAWood#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxa = 2000;typedef long long LL;int a, b;inline LL Gcd(LL x, LL y) {return y == 0 ? x : Gcd(y, x % y);}int euler_phi(int n) {int m = (int)sqrt(n + 0.5);int ans = n;for(int i = 2; i <= m; i++) if(n % i == 0){ans = ans / i * (i - 1);while(n % i == 0) n /= i;}if(n > 1) ans = ans / n * (n - 1);return ans;}int main() {while(scanf("%d%d", &a, &b) == 2 && a) {LL sum = 4LL * a * b + 2 * (a + b);//树的总个数 LL trees = 0;for(int x = 1; x <= a; x++) {int k = b / x;trees += (LL)euler_phi(x) * k;for(int y = k * x + 1; y <= b; y++) {if(Gcd(y, x) == 1) trees++;}}trees *= 4; trees += 4;double ans = (double)trees / sum;printf("%.7lf\n", ans);}}/*3 20 0*/

原创粉丝点击