GCD and LCM

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 3379    Accepted Submission(s): 1482

Problem Description
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x, y, z) = L? 
Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the least common multiple of x, y and z. 
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.
 
Input
First line comes an integer T (T <= 12), telling the number of test cases. 
The next T lines, each contains two positive 32-bit signed integers, G and L. 
It’s guaranteed that each answer will fit in a 32-bit signed integer.
 
Output
For each test case, print one line with the number of solutions satisfying the conditions above.
 
Sample Input
2
6 72
7 33
 
Sample Output
72
0

gcd(x,y,z) == G, lcm(x,y,z) == L

x' = x /G,y' = y /G ,z' = z / G;   gcd( x', y',z') == 1,lcm(x',y',z') == L/G

这样的话对t = L/G 这个数进行素因子分解,t = p1^t1 * p2^t2 * p3^t3 ..... * pn ^tn;

满足上面条件的x,y,z一定为这样的形式。
x' = p1^i1 * p2^i2 *```* pn^in.
y' = p1^j1 * p2^j2 * ```*pn^jn.
z' = p1^k1 * p2^k2 * ```*pn^kn.
为了满足上面的条件,对于p1,一定有max(i1,j1,k1) = t1和min(i1,j1,k1) =0;

因为gcd(p1^i1,p1^j1,p1^k1)== 1  → min(i1,j1,k1) == 0;lcm(p1^i1,p1^j1,p1^k1) == p1^t1   => max(i1,j1,k1) == t1;

所以我们现在要做的是把L/G分解成n个素因数相乘,比如:28=2*2*7=2^2 * 7

对于每一个p来说,三个数的集合一定是{ 0, t, x | 0≤x≤t }

  1. x = 0 或 x = t:这种情况有= 6 种
  2. 0 < x < t:这种情况x的取值可以为 0~t 的整数,一共有 t-1 个,而每一个数,都可以有种排列方法,就是6*(t-1)

    所以对每一个P来说,最后一共有 6*t 种取法 。

举个例子:252=2*2*7=2^2 * 3^3 * 7 一共有6*2+6*3+6=36种不同的(x,y,z)序列。

而如果L%G!=0,自然就没有解

#include <iostream>
using namespace std;

int f1(int n) {
    , i = ;
    ) {
        ;
        ){
        ) {
            t++;
            n /= i;
        }
            res *=  * t;
        }
            i++;
    }
    return res;
}
int main() {
    int T;
    cin >> T;
    while (T--) {
        int G, L;
        cin >> G >> L;
        )
            cout <<  << endl;
        else
            cout << f1(L / G) << endl;
    }
    ;
}

数论——算数基本定理 - HDU 4497 GCD and LCM的更多相关文章

  1. HDU 4497 GCD and LCM(数论+容斥原理)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  2. hdu 4497 GCD and LCM 数学

    GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  3. HDU 4497 GCD and LCM (合数分解)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  4. hdu 4497 GCD and LCM (非原创)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  5. HDU 4497 GCD and LCM (数论)

    题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组. 题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数 那么x = p1^x1 * ...

  6. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  7. hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)

    质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm  / gcd 质分解,统计每个质因子的个数,然后 ...

  8. HDU 4497 GCD and LCM (分解质因数)

    链接 :  http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...

  9. HDU 4497 GCD and LCM 素因子分解+ gcd 和 lcm

    题意: 给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性 思路: 将x , y , z进行素因子分解 素因子的幂次 x a1 a ...

随机推荐

  1. TRUNCATE TABLE 与 DELETE的区别

    delete from aatruncate table aa 区别1.delete from后面可以写条件,truncate不可以2.delete from记录是一条条删的,所删除的每行记录都会进日 ...

  2. bnu 10805 矩形神码的 平面向量的运行

    矩形神码的 Time Limit: 1000ms Memory Limit: 65536KB Special Judge   64-bit integer IO format: %lld      J ...

  3. ADO.NET对象模型之间的关系

    ADO.Net支持两种访问数据的模型:无连接模式和连接模式 无连接模式将数据下载到客户机器上,并在客户机上将数据封装到内存中, 可以向访问本地关系数据库一样访问内存中的数据(例如DataSet), 连 ...

  4. 关于this的全面解析(call,apply,new)

    我们在写代码的时候,时常会被this弄的傻傻分不清楚,看源码的时候也经常被call啊apply啊弄的头皮发麻.this到底是什么?本文主要根据书上和实际应用做了一些归纳.一般情况下this有4种绑定规 ...

  5. toast, 警告窗

    //浮动提示框 1秒后消失 toast(msg, isError, sec) { var div = $('#toast'); div.html(msg); div.css({visibility: ...

  6. Android 获取SD卡的图片资源

    首先我先获得SD卡下的根目录路径: privateString isSdcard(){ File sdcardDir=null; boolean isSDExist=Environment.getEx ...

  7. BubblePopupWindow

    Android 实现各个方向的气泡弹窗,可控制气泡尖角偏移量. https://github.com/smuyyh/BubblePopupWindow 截图 使用: BubblePopupWindow ...

  8. vue组件编写知识点

  9. Linux常用命令(一)————查找和替换

    1. 查找一个字符串 一个字符串是一行上的一个或几个字符.    为查找一个字符串,在vi命令模式下键入“/”,后面跟要查找的字符串,再按回车.vi将光标定位在该串下一次出现的地方上.键入n跳到该串的 ...

  10. Python json与pickle

    这是用于序列化的两个模块: • json: 用于字符串和python数据类型间进行转换 • pickle: 用于python特有的类型和python的数据类型间进行转换 Json模块提供了四个功能:d ...