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. MUI框架 picker日期选择器实例

    MUI官方文档点我 (一)准备工作,下载相关的js.cs文件,地址 (二)新建普通html页面 1)引入相关js.cs文件 2) 一个input,记录下id: <form> <lab ...

  2. 使用VScode 的插件

    使用vscode的插件实现快捷开发 ASP.NET Core Snippets  :HomeController, Startup, ProgramFile and many more starts ...

  3. linux的日常经常使用的命令

    现在经常用到linux命令,又时候回忘记,我就做个小笔记,大家也可以补充补充.....可以评论一下,我会截图做笔记的 netstat -ntlp //查看当前系统进程和端口等信息 tail -f fi ...

  4. 4.spring di

    spring di,即依赖注入,从应用的浅显意义来讲就是对属性赋值 1.用setter赋值,在spring的applicationContext.xml配置文件的bean下的property标签 属性 ...

  5. python学习之老男孩python全栈第九期_day023知识点总结——类和对象命名空间、组合

    一. 类和对象命名空间类里 可以定义两种属性: 1. 静态属性 2. 动态属性 class Course: language = 'Chinese' def __init__(self, teache ...

  6. Runtime 打开记事本

    package com.direct.str; import java.io.IOException; public class RunTimeDemo { /** * @param args */ ...

  7. js 对象数组去重

    var arr = [{ "name": "ZYTX", "age": "Y13xG_4wQnOWK1QwJLgg11d0pS4h ...

  8. html5 区块与内联div 与span html块级元素

    HTML <div> 和 <span> HTML 列表 HTML 类 可以通过 <div> 和 <span> 将 HTML 元素组合起来. HTML 块 ...

  9. less教程

    平时在工作中,偶尔会遇到老大让你修改原来写好的样式,如果修改的多的话,修改起来是非常麻烦的.他不像js一样,定义变量.函数,需要修改某些值,直接修改方法就行了.less的出现,恰恰帮我们解决了这个问题 ...

  10. 数据预处理(Python scikit-learn)

    在机器学习任务中,经常会对数据进行预处理.如尺度变换,标准化,二值化,正规化.至于采用哪种方法更有效,则与数据分布和采用算法有关.不同算法对数据的假设不同,可能需要不同的变换,而且有时无需进行变换,也 ...