Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4497
Test instructions: Known gcd (x, y, z) = G,LCM (x, y, z) = L. Tell you G, L, how many groups are required (x, Y, z) to satisfy the requirements, and consider the order.
Idea: if l%g! = 0 Obviously does not exist such (x, Y, z), the opposite certainly exists. The specific method is to l/g decomposition of the mass factor, get: l/g = p1^t1 * p2^t2 * ... * pk^tk, we consider any one factor pi^ti, at this time (x/g, y/g, z/g) = (x0, y0,z0) will x0,y0,z0 separate decomposition of the mass factor, to obtain the corresponding Bit for pi^t1, PI^T2,PI^T3, in order to meet the requirements, (T1, T2, T3) must have a 0 (three number coprime), (T1, T2, T3) must have a TI and the remaining one is less than or equal to TI (three number of least common multiple for l/g). Min (t1, t2, T3) = 0, max (t1, t2, t3) = Ti, all cases are 6*ti (permutation or repulsion principle), and the final answer is (6*T1) * (6*T2) * ... * (6*TK).
Code
1#include <cstdio>2 3 intMain ()4 {5 intncase;6scanf"%d", &ncase);7 while(ncase--) {8 intL, G;9scanf"%d%d", &g, &L);Ten ifLG) { Oneprintf"0\n"); A Continue; - } -L/=G; the intAns =1; - for(inti =2; I * I <= L; ++i) { - if(L% i = =0) { - intt =0; + while(L% i = =0) { -L/=i; +++T; A } atAns *= (6*t); - } - } - if(L! =1) Ans *=6; -printf"%d\n", ans); - } in return 0; -}
HDU 4497 GCD and LCM (decomposition mass factor + permutation combination)