1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string.h> using namespace std;
const int MAXN = 10000;
vector<int> PrimerTable;
int PrimeFactor[1230];
void InitPrimerTable() { bool IsNotP[10001]; memset(IsNotP, false, sizeof(IsNotP)); for (int i = 2; i <= MAXN; ++i) { for (int j = i << 1; j <= MAXN; j += i) { IsNotP[j] = true; } } for (int i = 2; i <= MAXN; ++i) { if (IsNotP[i] == false) { PrimerTable.push_back(i); } } }
int p, q, r, s;
void AddPerFactor(int n, const int& d) { for (int i = 0; i < PrimerTable.size(); ++i) { while (n % PrimerTable[i] == 0) { n /= PrimerTable[i]; PrimeFactor[i] += d; } } }
void AddToFactor(const int& n, const int& d) { for (int i = 1; i <= n; ++i) { AddPerFactor(i, d); } }
void AddAllFactor() { AddToFactor(p, 1); AddToFactor(r - s, 1); AddToFactor(s, 1); AddToFactor(p - q, -1); AddToFactor(q, -1); AddToFactor(r, -1); }
double QPower(int a, int b) { double Ans = 1; bool IsPositive = true; if (b < 0) { b *= -1; IsPositive = false; } while (b > 0) { if (b & 1) { Ans *= a; } a *= a; b >>= 1; } return IsPositive ? Ans : 1 / Ans; }
double PrimeFactorToAns() { double Ans = 1.; for (int i = 0; i < PrimerTable.size(); ++i) { Ans *= QPower(PrimerTable[i], PrimeFactor[i]); } return Ans; }
int main(){ InitPrimerTable(); while (cin >> p >> q >> r >> s) { memset(PrimeFactor, 0, sizeof(PrimeFactor)); AddAllFactor(); printf("%.5lf\n", PrimeFactorToAns()); } return 0;
}
|