1#include <cstdio>2#include <cstring>3#include <cmath>4#include <vector>5#include <iostream>6 using namespacestd;7 8 Const intMAXN =10000;9vector<int>primes;Ten intE[MAXN]; One A /** - add_factorial (int n, int d) calculation (n!) ^d, the idea is this: - first, the function of Add_integer (int n, int d) is clarified: the exponent corresponding to the mass factor of n is obtained. the n! is the relation of the multiplication, so the exponent corresponding to the mass factor of n is solved, and the value of the original solution is - accumulate. E[i] + = D; When d = 1 means n can be divisible by primes[i], i.e. primes[i] - is a qualitative factor of n, in the position of E[i] +1. - The complete execution of the function is the code of the unique decomposition theorem. The code is used to solve the + n! = p1^a1 * P2^A2 * p3^a3 * *pn^an - */ + A //multiply or divide by N. d=0 represents multiplication, d=-1 represents the addition at voidAdd_integer (intNintD) {///The index of the mass factor corresponding to n - for(inti =0; I < primes.size (); i++) { - while(n% primes[i] = =0) {///Index of the cyclic finding of the corresponding mass factor primes[i] -N/=Primes[i]; -E[i] + =D; - } in if(n = =1) Break;//save time by terminating the cycle prematurely - } to } + - voidAdd_factorial (intNintd) { the for(inti =1; I <= N; i++) * Add_integer (i, d); $ }Panax Notoginseng - BOOLIs_prime (intN) { the intm = Floor (sqrt (n) +0.5); + for(intA =2; A <= m; a++) A if(n% A = =0)return false; the return true; + } - $ intMain () { $ for(inti =2; I <=10000; i++)///solving the prime number between 2-10000 - if(Is_prime (i)) primes.push_back (i); - intp, Q, R, S; the while(CIN >> P >> q >> r >>s) { -Memset (E,0,sizeof(e));Wuyi ///C (p,q) theAdd_factorial (P,1); -Add_factorial (Q,-1); WuAdd_factorial (P-q,-1); - ///C (r,s) AboutAdd_factorial (R,-1); $Add_factorial (s),1); -Add_factorial (R-s,1); - DoubleAns =1; - for(inti =0; I < primes.size (); i++) AAns *=Pow (primes[i], e[i]); +printf"%.5lf\n", ans); the } - return 0; $}
Rujia Example 10-3 selection and division