HDU 4497 GCD and LCM (decomposition mass factor + permutation combination)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.