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. 如何在没有https环境下使用webrtc

    新版本的webrtc使用需要Https,但是在内网开发调试时,要配置Https环境比较麻烦,下面的方法是教你如何在http下使用webrtc 1,点桌面上的Chrome图票,右键->属性,把目票 ...

  2. MVC官方教程索引

    1.MVC教程首页http://www.asp.net/learn/mvc/?lang=cs 2.MVC概况2.1创建一个基于数据库的"电影"web应用http://www.asp ...

  3. Echarts 有点难度的柱状图

    本次的难点在于交叉传数据,又要把四组20个不同日期 显示上! 先看效果图: 数据传递方式:图 function func_echarts_2ba() { var echarts_2bar = echa ...

  4. 撩课-Web大前端每天5道面试题-Day2

    1.伪类与伪元素的区别? 1) 定义区别 伪类 伪类用于选择DOM树之外的信息,或是不能用简单选择器进行表示的信息. 前者包含那些匹配指定状态的元素,比如:visited,:active:后者包含那些 ...

  5. 1.Java设计模式-工厂模式

    1.简单工厂模式(Factory Method) 常用的工厂模式是静态工厂模式,利用static修饰方法,作为一种类似于常见的工具类Utils等辅助效果,一般情况下工厂类不需要实例化. //1.定义一 ...

  6. 【SSH网上商城项目实战19】订单信息的级联入库以及页面的缓存问题

          转自: https://blog.csdn.net/eson_15/article/details/51433247 购物车这一块还剩最后两个问题,就是订单信息的级联入库和页面缓存,这里的 ...

  7. Cookie介绍

    1.Http协议与Cookie Cookie(小量信息)是HTTP协议指定的!先由服务器保存Cookie到浏览器,而下次浏览器请求服务器时把上一次请求得到Cookie再归还给服务器 由服务器创建保存到 ...

  8. SQL Server 中位数、标准差、平均数

    create table examines ( ,) NOT NULL, ) NULL, [ph_score] [int] NULL ) SELECT dept_name, AVG(sp) as '中 ...

  9. VC+++ 操作word

    最近完成了一个使用VC++ 操作word生成扫描报告的功能,在这里将过程记录下来,开发环境为visual studio 2008 导入接口 首先在创建的MFC项目中引入word相关组件 右键点击 项目 ...

  10. java 自定义泛型

    package com.direct.demo; import java.util.ArrayList; import java.util.HashMap; import java.util.Link ...